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
This commit is contained in:
Joe Darcy 2022-09-13 16:51:01 +00:00
parent 6f2223faa1
commit 1dc5039fed
3 changed files with 33 additions and 3 deletions
src/java.base/share/classes/java/lang/reflect
test/jdk/java/lang/reflect/AccessFlag

@ -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;
@ -324,7 +325,7 @@ public enum AccessFlag {
* 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) {
@ -470,6 +471,7 @@ public enum AccessFlag {
* @throws NullPointerException if the parameter is {@code null}
*/
public Set<Location> locations(ClassFileFormatVersion cffv) {
Objects.requireNonNull(cffv);
if (cffvToLocations == null) {
return locations;
} else {

@ -23,7 +23,7 @@
/*
* @test
* @bug 8266670
* @bug 8266670 8293626
* @summary Basic tests of AccessFlag
*/
@ -42,6 +42,7 @@ public class BasicAccessFlagTest {
testMaskOrdering();
testDisjoint();
testMaskToAccessFlagsPositive();
testLocationsNullHandling();
}
/*
@ -147,4 +148,15 @@ public class BasicAccessFlagTest {
}
}
}
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
}
}
}
}

@ -23,7 +23,7 @@
/*
* @test
* @bug 8289106
* @bug 8289106 8293627
* @summary Tests of AccessFlag.locations(ClassFileFormatVersion)
*/
@ -78,6 +78,7 @@ public class VersionedLocationsTest {
testTwoStepAccessFlags();
testSynthetic();
testStrict();
testLatestMatch();
}
/**
@ -269,4 +270,19 @@ public class VersionedLocationsTest {
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);
}
}
}
}