8291734: Return accurate ACC_SUPER access flag for classes
Reviewed-by: mchung
This commit is contained in:
parent
e4925a3959
commit
68af7c1365
@ -1346,16 +1346,18 @@ public final class Class<T> implements java.io.Serializable,
|
||||
* @since 20
|
||||
*/
|
||||
public Set<AccessFlag> accessFlags() {
|
||||
// This likely needs some refinement. Exploration of hidden
|
||||
// classes, array classes. Location.CLASS allows SUPER and
|
||||
// AccessFlag.MODULE which INNER_CLASS forbids. INNER_CLASS
|
||||
// allows PRIVATE, PROTECTED, and STATIC, which are not
|
||||
// allowed on Location.CLASS.
|
||||
return AccessFlag.maskToAccessFlags(getModifiers(),
|
||||
(isMemberClass() || isLocalClass() ||
|
||||
isAnonymousClass() || isArray()) ?
|
||||
AccessFlag.Location.INNER_CLASS :
|
||||
AccessFlag.Location.CLASS);
|
||||
// Location.CLASS allows SUPER and AccessFlag.MODULE which
|
||||
// INNER_CLASS forbids. INNER_CLASS allows PRIVATE, PROTECTED,
|
||||
// and STATIC, which are not allowed on Location.CLASS.
|
||||
// Use getClassAccessFlagsRaw to expose SUPER status.
|
||||
var location = (isMemberClass() || isLocalClass() ||
|
||||
isAnonymousClass() || isArray()) ?
|
||||
AccessFlag.Location.INNER_CLASS :
|
||||
AccessFlag.Location.CLASS;
|
||||
return AccessFlag.maskToAccessFlags((location == AccessFlag.Location.CLASS) ?
|
||||
getClassAccessFlagsRaw() :
|
||||
getModifiers(),
|
||||
location);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8266670
|
||||
* @bug 8266670 8291734
|
||||
* @summary Test expected AccessFlag's on classes.
|
||||
*/
|
||||
|
||||
@ -46,16 +46,11 @@ import java.util.*;
|
||||
* return the Class object created from a module-info.class
|
||||
* file. Therefore, this test does not attempt to probe the setting of
|
||||
* that access flag.
|
||||
*
|
||||
* For a class, the VM must treat the class as if the ACC_SUPER bit
|
||||
* were set, but that bit is cleared by HotSpot when it is passed out
|
||||
* to the core reflection libraries. Therefore, this test does not
|
||||
* attempt to check whether or not AccessFlag.SUPER is set.
|
||||
*/
|
||||
@ExpectedClassFlags("[PUBLIC, FINAL]")
|
||||
@ExpectedClassFlags("[PUBLIC, FINAL, SUPER]")
|
||||
public final class ClassAccessFlagTest {
|
||||
public static void main(String... args) {
|
||||
// Top-level and axuillary classes; i.e. non-inner classes
|
||||
// Top-level and auxiliary classes; i.e. non-inner classes
|
||||
Class<?>[] testClasses = {
|
||||
ClassAccessFlagTest.class,
|
||||
TestInterface.class,
|
||||
@ -226,7 +221,7 @@ public final class ClassAccessFlagTest {
|
||||
interface TestInterface {}
|
||||
|
||||
|
||||
@ExpectedClassFlags("[FINAL, ENUM]")
|
||||
@ExpectedClassFlags("[FINAL, SUPER, ENUM]")
|
||||
enum TestOuterEnum {
|
||||
INSTANCE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user