From f398da720014432dc9f827521993579c9e10002c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 20 Sep 2021 15:14:42 +1000 Subject: [PATCH] Fix #6868 Fix copy constructors (#6872) * Fix #6868 Fix copy constructors Fixed copy constructors found by static code analysis Signed-off-by: Greg Wilkins --- .../jetty/server/HttpConfiguration.java | 1 + .../eclipse/jetty/webapp/ClassMatcher.java | 3 +- .../jetty/webapp/ClassMatcherTest.java | 70 +++++++++++-------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java index 563de9534cf6..2c73ff993c8d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java @@ -144,6 +144,7 @@ public HttpConfiguration(HttpConfiguration config) _responseCookieCompliance = config._responseCookieCompliance; _notifyRemoteAsyncErrors = config._notifyRemoteAsyncErrors; _relativeRedirectAllowed = config._relativeRedirectAllowed; + _uriCompliance = config._uriCompliance; } /** diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java index 3fe7d932b609..b726815968df 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClassMatcher.java @@ -496,6 +496,7 @@ public ClassMatcher() { } + @SuppressWarnings("CopyConstructorMissesField") public ClassMatcher(ClassMatcher patterns) { if (patterns != null) @@ -676,7 +677,7 @@ private void addAll(String[] classes) */ public String[] getPatterns() { - return toArray(new String[_entries.size()]); + return toArray(new String[0]); } /** diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java index 20f1d163189e..54811dcccca5 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClassMatcherTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -119,6 +120,13 @@ public void testMatchAll() assertTrue(_pattern.match("org.example.Anything$Else")); } + @Test + public void testCopy() + { + ClassMatcher copy = new ClassMatcher(_pattern); + assertThat(copy.toString(), is(_pattern.toString())); + } + @Test public void testMatchFundamentalExcludeSpecific() { @@ -145,9 +153,9 @@ public void testIncludedLocations() throws Exception ClassMatcher pattern = new ClassMatcher(); pattern.include("something"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); // Add directory for both JVM classes pattern.include(locString.toASCIIString()); @@ -155,14 +163,14 @@ public void testIncludedLocations() throws Exception // Add jar for individual class and classes directory pattern.include(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); pattern.add("-java.lang.String"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); } @SuppressWarnings("restriction") @@ -183,9 +191,9 @@ public void testIncludedLocationsOrModule() throws Exception ClassMatcher pattern = new ClassMatcher(); pattern.include("something"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); // Add module for all JVM base classes pattern.include("jrt:/java.base"); @@ -193,14 +201,14 @@ public void testIncludedLocationsOrModule() throws Exception // Add jar for individual class and classes directory pattern.include(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); pattern.add("-java.lang.String"); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); } @SuppressWarnings("restriction") @@ -224,9 +232,9 @@ public void testExcludeLocationsOrModule() throws Exception // include everything pattern.include("."); - assertThat(pattern.match(String.class), Matchers.is(true)); - assertThat(pattern.match(Test.class), Matchers.is(true)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); + assertThat(pattern.match(String.class), is(true)); + assertThat(pattern.match(Test.class), is(true)); + assertThat(pattern.match(ClassMatcherTest.class), is(true)); // Add directory for both JVM classes pattern.exclude("jrt:/java.base/"); @@ -234,9 +242,9 @@ public void testExcludeLocationsOrModule() throws Exception // Add jar for individual class and classes directory pattern.exclude(locJunit.toString(), locTest.toString()); - assertThat(pattern.match(String.class), Matchers.is(false)); - assertThat(pattern.match(Test.class), Matchers.is(false)); - assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); + assertThat(pattern.match(String.class), is(false)); + assertThat(pattern.match(Test.class), is(false)); + assertThat(pattern.match(ClassMatcherTest.class), is(false)); } @Test @@ -248,33 +256,33 @@ public void testWithNullLocation() throws Exception IncludeExcludeSet locations = new IncludeExcludeSet<>(ByLocationOrModule.class); //Test no name or location includes or excludes - should match - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); names.include(matcher.newEntry("a.b.", true)); names.exclude(matcher.newEntry("d.e.", false)); //Test explicit include by name no locations - should match - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); //Test explicit exclude by name no locations - should not match - assertThat(ClassMatcher.combine(names, "d.e.f", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "d.e.f", locations, NULL_SUPPLIER), is(false)); //Test include by name with location includes - should match locations.include(matcher.newEntry("file:/foo/bar", true)); - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(true)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(true)); //Test include by name but with location exclusions - should not match locations.clear(); locations.exclude(matcher.newEntry("file:/high/low", false)); - assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "a.b.c", locations, NULL_SUPPLIER), is(false)); //Test neither included or excluded by name, but with location exclusions - should not match - assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), is(false)); //Test neither included nor excluded by name, but with location inclusions - should not match locations.clear(); locations.include(matcher.newEntry("file:/foo/bar", true)); - assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), Matchers.is(false)); + assertThat(ClassMatcher.combine(names, "g.b.r", locations, NULL_SUPPLIER), is(false)); } @Test