mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
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:
parent
6f2223faa1
commit
1dc5039fed
3 changed files with 33 additions and 3 deletions
|
@ -26,6 +26,7 @@
|
||||||
package java.lang.reflect;
|
package java.lang.reflect;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -324,7 +325,7 @@ public enum AccessFlag {
|
||||||
* major versions 46 through 60, inclusive (JVMS {@jvms 4.6}),
|
* major versions 46 through 60, inclusive (JVMS {@jvms 4.6}),
|
||||||
* corresponding to Java SE 1.2 through 16.
|
* 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>>() {
|
new Function<ClassFileFormatVersion, Set<Location>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<Location> apply(ClassFileFormatVersion cffv) {
|
public Set<Location> apply(ClassFileFormatVersion cffv) {
|
||||||
|
@ -470,6 +471,7 @@ public enum AccessFlag {
|
||||||
* @throws NullPointerException if the parameter is {@code null}
|
* @throws NullPointerException if the parameter is {@code null}
|
||||||
*/
|
*/
|
||||||
public Set<Location> locations(ClassFileFormatVersion cffv) {
|
public Set<Location> locations(ClassFileFormatVersion cffv) {
|
||||||
|
Objects.requireNonNull(cffv);
|
||||||
if (cffvToLocations == null) {
|
if (cffvToLocations == null) {
|
||||||
return locations;
|
return locations;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8266670
|
* @bug 8266670 8293626
|
||||||
* @summary Basic tests of AccessFlag
|
* @summary Basic tests of AccessFlag
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ public class BasicAccessFlagTest {
|
||||||
testMaskOrdering();
|
testMaskOrdering();
|
||||||
testDisjoint();
|
testDisjoint();
|
||||||
testMaskToAccessFlagsPositive();
|
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
|
* @test
|
||||||
* @bug 8289106
|
* @bug 8289106 8293627
|
||||||
* @summary Tests of AccessFlag.locations(ClassFileFormatVersion)
|
* @summary Tests of AccessFlag.locations(ClassFileFormatVersion)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ public class VersionedLocationsTest {
|
||||||
testTwoStepAccessFlags();
|
testTwoStepAccessFlags();
|
||||||
testSynthetic();
|
testSynthetic();
|
||||||
testStrict();
|
testStrict();
|
||||||
|
testLatestMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,4 +270,19 @@ public class VersionedLocationsTest {
|
||||||
compareLocations(expected, STRICT, cffv);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue