HADOOP-11309. System class pattern package.Foo should match package.Foo$Bar, too. Contributed by Gera Shegalov

(cherry picked from commit b4ca727690)
This commit is contained in:
Jason Lowe 2014-11-18 17:22:21 +00:00
parent 09df35e51d
commit 5125a8e59e
3 changed files with 29 additions and 11 deletions

View File

@ -91,6 +91,9 @@ Release 2.7.0 - UNRELEASED
HADOOP-11311. Restrict uppercase key names from being created with JCEKS.
(wang)
HADOOP-11309. System class pattern package.Foo should match
package.Foo$Bar, too (Gera Shegalov via jlowe)
Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES

View File

@ -228,10 +228,13 @@ public class ApplicationClassLoader extends URLClassLoader {
c = c.substring(1);
result = false;
}
if (c.endsWith(".") && canonicalName.startsWith(c)) {
return result;
} else if (canonicalName.equals(c)) {
return result;
if (canonicalName.startsWith(c)) {
if ( c.endsWith(".") // package
|| canonicalName.length() == c.length() // class
|| canonicalName.length() > c.length() // nested
&& canonicalName.charAt(c.length()) == '$' ) {
return result;
}
}
}
}

View File

@ -90,15 +90,27 @@ public class TestApplicationClassLoader {
@Test
public void testIsSystemClass() {
assertFalse(isSystemClass("org.example.Foo", null));
assertTrue(isSystemClass("org.example.Foo", classes("org.example.Foo")));
assertTrue(isSystemClass("/org.example.Foo", classes("org.example.Foo")));
assertTrue(isSystemClass("org.example.Foo", classes("org.example.")));
assertTrue(isSystemClass("net.example.Foo",
testIsSystemClassInternal("");
}
@Test
public void testIsSystemNestedClass() {
testIsSystemClassInternal("$Klass");
}
private void testIsSystemClassInternal(String nestedClass) {
assertFalse(isSystemClass("org.example.Foo" + nestedClass, null));
assertTrue(isSystemClass("org.example.Foo" + nestedClass,
classes("org.example.Foo")));
assertTrue(isSystemClass("/org.example.Foo" + nestedClass,
classes("org.example.Foo")));
assertTrue(isSystemClass("org.example.Foo" + nestedClass,
classes("org.example.")));
assertTrue(isSystemClass("net.example.Foo" + nestedClass,
classes("org.example.,net.example.")));
assertFalse(isSystemClass("org.example.Foo",
assertFalse(isSystemClass("org.example.Foo" + nestedClass,
classes("-org.example.Foo,org.example.")));
assertTrue(isSystemClass("org.example.Bar",
assertTrue(isSystemClass("org.example.Bar" + nestedClass,
classes("-org.example.Foo.,org.example.")));
}