Fix #6868 Fix copy constructors (#6872)

* Fix #6868 Fix copy constructors

Fixed copy constructors found by static code analysis

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2021-09-20 15:14:42 +10:00 committed by GitHub
parent 4793092f9d
commit f398da7200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 32 deletions

View File

@ -144,6 +144,7 @@ public class HttpConfiguration implements Dumpable
_responseCookieCompliance = config._responseCookieCompliance; _responseCookieCompliance = config._responseCookieCompliance;
_notifyRemoteAsyncErrors = config._notifyRemoteAsyncErrors; _notifyRemoteAsyncErrors = config._notifyRemoteAsyncErrors;
_relativeRedirectAllowed = config._relativeRedirectAllowed; _relativeRedirectAllowed = config._relativeRedirectAllowed;
_uriCompliance = config._uriCompliance;
} }
/** /**

View File

@ -496,6 +496,7 @@ public class ClassMatcher extends AbstractSet<String>
{ {
} }
@SuppressWarnings("CopyConstructorMissesField")
public ClassMatcher(ClassMatcher patterns) public ClassMatcher(ClassMatcher patterns)
{ {
if (patterns != null) if (patterns != null)
@ -676,7 +677,7 @@ public class ClassMatcher extends AbstractSet<String>
*/ */
public String[] getPatterns() public String[] getPatterns()
{ {
return toArray(new String[_entries.size()]); return toArray(new String[0]);
} }
/** /**

View File

@ -27,6 +27,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat; 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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -119,6 +120,13 @@ public class ClassMatcherTest
assertTrue(_pattern.match("org.example.Anything$Else")); assertTrue(_pattern.match("org.example.Anything$Else"));
} }
@Test
public void testCopy()
{
ClassMatcher copy = new ClassMatcher(_pattern);
assertThat(copy.toString(), is(_pattern.toString()));
}
@Test @Test
public void testMatchFundamentalExcludeSpecific() public void testMatchFundamentalExcludeSpecific()
{ {
@ -145,9 +153,9 @@ public class ClassMatcherTest
ClassMatcher pattern = new ClassMatcher(); ClassMatcher pattern = new ClassMatcher();
pattern.include("something"); pattern.include("something");
assertThat(pattern.match(String.class), Matchers.is(false)); assertThat(pattern.match(String.class), is(false));
assertThat(pattern.match(Test.class), Matchers.is(false)); assertThat(pattern.match(Test.class), is(false));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); assertThat(pattern.match(ClassMatcherTest.class), is(false));
// Add directory for both JVM classes // Add directory for both JVM classes
pattern.include(locString.toASCIIString()); pattern.include(locString.toASCIIString());
@ -155,14 +163,14 @@ public class ClassMatcherTest
// Add jar for individual class and classes directory // Add jar for individual class and classes directory
pattern.include(locJunit.toString(), locTest.toString()); pattern.include(locJunit.toString(), locTest.toString());
assertThat(pattern.match(String.class), Matchers.is(true)); assertThat(pattern.match(String.class), is(true));
assertThat(pattern.match(Test.class), Matchers.is(true)); assertThat(pattern.match(Test.class), is(true));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); assertThat(pattern.match(ClassMatcherTest.class), is(true));
pattern.add("-java.lang.String"); pattern.add("-java.lang.String");
assertThat(pattern.match(String.class), Matchers.is(false)); assertThat(pattern.match(String.class), is(false));
assertThat(pattern.match(Test.class), Matchers.is(true)); assertThat(pattern.match(Test.class), is(true));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); assertThat(pattern.match(ClassMatcherTest.class), is(true));
} }
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
@ -183,9 +191,9 @@ public class ClassMatcherTest
ClassMatcher pattern = new ClassMatcher(); ClassMatcher pattern = new ClassMatcher();
pattern.include("something"); pattern.include("something");
assertThat(pattern.match(String.class), Matchers.is(false)); assertThat(pattern.match(String.class), is(false));
assertThat(pattern.match(Test.class), Matchers.is(false)); assertThat(pattern.match(Test.class), is(false));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); assertThat(pattern.match(ClassMatcherTest.class), is(false));
// Add module for all JVM base classes // Add module for all JVM base classes
pattern.include("jrt:/java.base"); pattern.include("jrt:/java.base");
@ -193,14 +201,14 @@ public class ClassMatcherTest
// Add jar for individual class and classes directory // Add jar for individual class and classes directory
pattern.include(locJunit.toString(), locTest.toString()); pattern.include(locJunit.toString(), locTest.toString());
assertThat(pattern.match(String.class), Matchers.is(true)); assertThat(pattern.match(String.class), is(true));
assertThat(pattern.match(Test.class), Matchers.is(true)); assertThat(pattern.match(Test.class), is(true));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); assertThat(pattern.match(ClassMatcherTest.class), is(true));
pattern.add("-java.lang.String"); pattern.add("-java.lang.String");
assertThat(pattern.match(String.class), Matchers.is(false)); assertThat(pattern.match(String.class), is(false));
assertThat(pattern.match(Test.class), Matchers.is(true)); assertThat(pattern.match(Test.class), is(true));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); assertThat(pattern.match(ClassMatcherTest.class), is(true));
} }
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
@ -224,9 +232,9 @@ public class ClassMatcherTest
// include everything // include everything
pattern.include("."); pattern.include(".");
assertThat(pattern.match(String.class), Matchers.is(true)); assertThat(pattern.match(String.class), is(true));
assertThat(pattern.match(Test.class), Matchers.is(true)); assertThat(pattern.match(Test.class), is(true));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true)); assertThat(pattern.match(ClassMatcherTest.class), is(true));
// Add directory for both JVM classes // Add directory for both JVM classes
pattern.exclude("jrt:/java.base/"); pattern.exclude("jrt:/java.base/");
@ -234,9 +242,9 @@ public class ClassMatcherTest
// Add jar for individual class and classes directory // Add jar for individual class and classes directory
pattern.exclude(locJunit.toString(), locTest.toString()); pattern.exclude(locJunit.toString(), locTest.toString());
assertThat(pattern.match(String.class), Matchers.is(false)); assertThat(pattern.match(String.class), is(false));
assertThat(pattern.match(Test.class), Matchers.is(false)); assertThat(pattern.match(Test.class), is(false));
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false)); assertThat(pattern.match(ClassMatcherTest.class), is(false));
} }
@Test @Test
@ -248,33 +256,33 @@ public class ClassMatcherTest
IncludeExcludeSet<Entry, URI> locations = new IncludeExcludeSet<>(ByLocationOrModule.class); IncludeExcludeSet<Entry, URI> locations = new IncludeExcludeSet<>(ByLocationOrModule.class);
//Test no name or location includes or excludes - should match //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.include(matcher.newEntry("a.b.", true));
names.exclude(matcher.newEntry("d.e.", false)); names.exclude(matcher.newEntry("d.e.", false));
//Test explicit include by name no locations - should match //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 //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 //Test include by name with location includes - should match
locations.include(matcher.newEntry("file:/foo/bar", true)); 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 //Test include by name but with location exclusions - should not match
locations.clear(); locations.clear();
locations.exclude(matcher.newEntry("file:/high/low", false)); 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 //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 //Test neither included nor excluded by name, but with location inclusions - should not match
locations.clear(); locations.clear();
locations.include(matcher.newEntry("file:/foo/bar", true)); 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 @Test