From 68af7c1365712773a56f19ce3453baebffd006f4 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Wed, 10 Aug 2022 19:55:57 +0000 Subject: [PATCH] 8291734: Return accurate ACC_SUPER access flag for classes Reviewed-by: mchung --- .../share/classes/java/lang/Class.java | 22 ++++++++++--------- .../AccessFlag/ClassAccessFlagTest.java | 13 ++++------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 4bd31a0c0b6..0d8f5b14952 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -1346,16 +1346,18 @@ public final class Class implements java.io.Serializable, * @since 20 */ public Set 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); } /** diff --git a/test/jdk/java/lang/reflect/AccessFlag/ClassAccessFlagTest.java b/test/jdk/java/lang/reflect/AccessFlag/ClassAccessFlagTest.java index ee8263ca08c..647029a011f 100644 --- a/test/jdk/java/lang/reflect/AccessFlag/ClassAccessFlagTest.java +++ b/test/jdk/java/lang/reflect/AccessFlag/ClassAccessFlagTest.java @@ -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; }