mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8219483: j.l.c.ClassDesc::nested(String, String...) doesn't throw NPE if any arg is null
Reviewed-by: darcy
This commit is contained in:
parent
5a264ba9db
commit
c7faef0785
2 changed files with 30 additions and 1 deletions
|
@ -213,7 +213,7 @@ public interface ClassDesc
|
||||||
* @param moreNestedNames the unqualified name(s) of the remaining levels of
|
* @param moreNestedNames the unqualified name(s) of the remaining levels of
|
||||||
* nested class
|
* nested class
|
||||||
* @return a {@linkplain ClassDesc} describing the nested class
|
* @return a {@linkplain ClassDesc} describing the nested class
|
||||||
* @throws NullPointerException if any argument is {@code null}
|
* @throws NullPointerException if any argument or its contents is {@code null}
|
||||||
* @throws IllegalStateException if this {@linkplain ClassDesc} does not
|
* @throws IllegalStateException if this {@linkplain ClassDesc} does not
|
||||||
* describe a class or interface type
|
* describe a class or interface type
|
||||||
* @throws IllegalArgumentException if the nested class name is invalid
|
* @throws IllegalArgumentException if the nested class name is invalid
|
||||||
|
@ -221,6 +221,11 @@ public interface ClassDesc
|
||||||
default ClassDesc nested(String firstNestedName, String... moreNestedNames) {
|
default ClassDesc nested(String firstNestedName, String... moreNestedNames) {
|
||||||
if (!isClassOrInterface())
|
if (!isClassOrInterface())
|
||||||
throw new IllegalStateException("Outer class is not a class or interface type");
|
throw new IllegalStateException("Outer class is not a class or interface type");
|
||||||
|
validateMemberName(firstNestedName, false);
|
||||||
|
requireNonNull(moreNestedNames);
|
||||||
|
for (String addNestedNames : moreNestedNames) {
|
||||||
|
validateMemberName(addNestedNames, false);
|
||||||
|
}
|
||||||
return moreNestedNames.length == 0
|
return moreNestedNames.length == 0
|
||||||
? nested(firstNestedName)
|
? nested(firstNestedName)
|
||||||
: nested(firstNestedName + Stream.of(moreNestedNames).collect(joining("$", "$", "")));
|
: nested(firstNestedName + Stream.of(moreNestedNames).collect(joining("$", "$", "")));
|
||||||
|
|
|
@ -306,4 +306,28 @@ public class ClassDescTest extends SymbolicDescTest {
|
||||||
assertEquals(s.resolveConstantDesc(LOOKUP), s);
|
assertEquals(s.resolveConstantDesc(LOOKUP), s);
|
||||||
assertEquals(s.describeConstable().get(), s);
|
assertEquals(s.describeConstable().get(), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNullNestedClasses() {
|
||||||
|
ClassDesc cd = ClassDesc.of("Bar");
|
||||||
|
try {
|
||||||
|
cd.nested(null);
|
||||||
|
fail("");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
// good
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
cd.nested("good", null);
|
||||||
|
fail("");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
// good
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
cd.nested("good", "goodToo", null);
|
||||||
|
fail("");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
// good
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue