Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8293626: AccessFlag::locations(ClassFileFormatVersion cffv) does not …
…throw NPEx when parameter is null

8293627: AccessFlag::locations(ClassFileFormatVersion cffv) and locations() results are inconsistent

Reviewed-by: mchung
  • Loading branch information
jddarcy committed Sep 13, 2022
1 parent 6f2223f commit 1dc5039
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Expand Up @@ -26,6 +26,7 @@
package java.lang.reflect;

import java.util.Collections;
import java.util.Objects;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -324,7 +325,7 @@ public Set<Location> apply(ClassFileFormatVersion cffv) {
* major versions 46 through 60, inclusive (JVMS {@jvms 4.6}),
* corresponding to Java SE 1.2 through 16.
*/
STRICT(Modifier.STRICT, true, Location.SET_METHOD,
STRICT(Modifier.STRICT, true, Location.EMPTY_SET,
new Function<ClassFileFormatVersion, Set<Location>>() {
@Override
public Set<Location> apply(ClassFileFormatVersion cffv) {
Expand Down Expand Up @@ -470,6 +471,7 @@ public Set<Location> locations() {
* @throws NullPointerException if the parameter is {@code null}
*/
public Set<Location> locations(ClassFileFormatVersion cffv) {
Objects.requireNonNull(cffv);
if (cffvToLocations == null) {
return locations;
} else {
Expand Down
14 changes: 13 additions & 1 deletion test/jdk/java/lang/reflect/AccessFlag/BasicAccessFlagTest.java
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8266670
* @bug 8266670 8293626
* @summary Basic tests of AccessFlag
*/

Expand All @@ -42,6 +42,7 @@ public static void main(String... args) throws Exception {
testMaskOrdering();
testDisjoint();
testMaskToAccessFlagsPositive();
testLocationsNullHandling();
}

/*
Expand Down Expand Up @@ -147,4 +148,15 @@ private static void testMaskToAccessFlagsPositive() {
}
}
}

private static void testLocationsNullHandling() {
for (var flag : AccessFlag.values() ) {
try {
flag.locations(null);
throw new RuntimeException("Did not get NPE on " + flag + ".location(null)");
} catch (NullPointerException npe ) {
; // Expected
}
}
}
}
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8289106
* @bug 8289106 8293627
* @summary Tests of AccessFlag.locations(ClassFileFormatVersion)
*/

Expand Down Expand Up @@ -78,6 +78,7 @@ public static void main(String... args) throws Exception {
testTwoStepAccessFlags();
testSynthetic();
testStrict();
testLatestMatch();
}

/**
Expand Down Expand Up @@ -269,4 +270,19 @@ private static void testStrict() {
compareLocations(expected, STRICT, cffv);
}
}

private static void testLatestMatch() {
// Verify accessFlag.locations() and
// accessFlag.locations(ClassFileFormatVersion.latest()) are
// consistent
var LATEST = ClassFileFormatVersion.latest();
for (var accessFlag : AccessFlag.values()) {
var locationSet = accessFlag.locations();
var locationLatestSet = accessFlag.locations(LATEST);
if (!locationSet.equals(locationLatestSet)) {
throw new RuntimeException("Unequal location sets for " + accessFlag);
}
}
}

}

1 comment on commit 1dc5039

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.