From 6a9778ac8c00d37a7b77f70bb1bf25f9374cfc2e Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 8 Aug 2024 07:57:10 +0300 Subject: [PATCH] Prefer immutable collections where possible --- .../org/gaul/s3proxy/CrossOriginResourceSharing.java | 8 ++++---- src/main/java/org/gaul/s3proxy/S3Proxy.java | 10 ++++++---- .../s3proxy/CrossOriginResourceSharingRuleTest.java | 8 +++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gaul/s3proxy/CrossOriginResourceSharing.java b/src/main/java/org/gaul/s3proxy/CrossOriginResourceSharing.java index a28a530c..f5ba9ba7 100644 --- a/src/main/java/org/gaul/s3proxy/CrossOriginResourceSharing.java +++ b/src/main/java/org/gaul/s3proxy/CrossOriginResourceSharing.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.regex.Matcher; @@ -28,7 +29,6 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,9 +58,9 @@ public final class CrossOriginResourceSharing { public CrossOriginResourceSharing() { // CORS Allow all - this(Lists.newArrayList(ALLOW_ANY_ORIGIN), SUPPORTED_METHODS, - Lists.newArrayList(ALLOW_ANY_HEADER), - Lists.newArrayList(EXPOSE_ALL_HEADERS), ""); + this(List.of(ALLOW_ANY_ORIGIN), SUPPORTED_METHODS, + List.of(ALLOW_ANY_HEADER), + List.of(EXPOSE_ALL_HEADERS), ""); } public CrossOriginResourceSharing(Collection allowedOrigins, diff --git a/src/main/java/org/gaul/s3proxy/S3Proxy.java b/src/main/java/org/gaul/s3proxy/S3Proxy.java index f136f1da..2078350b 100644 --- a/src/main/java/org/gaul/s3proxy/S3Proxy.java +++ b/src/main/java/org/gaul/s3proxy/S3Proxy.java @@ -28,6 +28,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.eclipse.jetty.http.HttpCompliance; @@ -291,10 +292,11 @@ public static Builder fromProperties(Properties properties) } builder.corsRules(new CrossOriginResourceSharing( - Lists.newArrayList(splitter.split(corsAllowOrigins)), - Lists.newArrayList(splitter.split(corsAllowMethods)), - Lists.newArrayList(splitter.split(corsAllowHeaders)), - Lists.newArrayList(splitter.split(corsExposedHeaders)), + ImmutableList.copyOf(splitter.split(corsAllowOrigins)), + ImmutableList.copyOf(splitter.split(corsAllowMethods)), + ImmutableList.copyOf(splitter.split(corsAllowHeaders)), + ImmutableList.copyOf(splitter.split( + corsExposedHeaders)), allowCredentials)); } diff --git a/src/test/java/org/gaul/s3proxy/CrossOriginResourceSharingRuleTest.java b/src/test/java/org/gaul/s3proxy/CrossOriginResourceSharingRuleTest.java index 988eb5de..7ea7a55c 100644 --- a/src/test/java/org/gaul/s3proxy/CrossOriginResourceSharingRuleTest.java +++ b/src/test/java/org/gaul/s3proxy/CrossOriginResourceSharingRuleTest.java @@ -20,8 +20,6 @@ import java.util.List; -import com.google.common.collect.Lists; - import org.junit.Before; import org.junit.Test; @@ -36,11 +34,11 @@ public void setUp() throws Exception { corsAll = new CrossOriginResourceSharing(); // CORS Configured corsCfg = new CrossOriginResourceSharing( - Lists.newArrayList("https://example\\.com", + List.of("https://example\\.com", "https://.+\\.example\\.com", "https://example\\.cloud"), - Lists.newArrayList("GET", "PUT"), - Lists.newArrayList("Accept", "Content-Type"), + List.of("GET", "PUT"), + List.of("Accept", "Content-Type"), List.of(), "true"); // CORS disabled