Skip to content

Commit 68af7c1

Browse files
committed
8291734: Return accurate ACC_SUPER access flag for classes
Reviewed-by: mchung
1 parent e4925a3 commit 68af7c1

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/java.base/share/classes/java/lang/Class.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -1346,16 +1346,18 @@ private Class<?> elementType() {
13461346
* @since 20
13471347
*/
13481348
public Set<AccessFlag> accessFlags() {
1349-
// This likely needs some refinement. Exploration of hidden
1350-
// classes, array classes. Location.CLASS allows SUPER and
1351-
// AccessFlag.MODULE which INNER_CLASS forbids. INNER_CLASS
1352-
// allows PRIVATE, PROTECTED, and STATIC, which are not
1353-
// allowed on Location.CLASS.
1354-
return AccessFlag.maskToAccessFlags(getModifiers(),
1355-
(isMemberClass() || isLocalClass() ||
1356-
isAnonymousClass() || isArray()) ?
1357-
AccessFlag.Location.INNER_CLASS :
1358-
AccessFlag.Location.CLASS);
1349+
// Location.CLASS allows SUPER and AccessFlag.MODULE which
1350+
// INNER_CLASS forbids. INNER_CLASS allows PRIVATE, PROTECTED,
1351+
// and STATIC, which are not allowed on Location.CLASS.
1352+
// Use getClassAccessFlagsRaw to expose SUPER status.
1353+
var location = (isMemberClass() || isLocalClass() ||
1354+
isAnonymousClass() || isArray()) ?
1355+
AccessFlag.Location.INNER_CLASS :
1356+
AccessFlag.Location.CLASS;
1357+
return AccessFlag.maskToAccessFlags((location == AccessFlag.Location.CLASS) ?
1358+
getClassAccessFlagsRaw() :
1359+
getModifiers(),
1360+
location);
13591361
}
13601362

13611363
/**

test/jdk/java/lang/reflect/AccessFlag/ClassAccessFlagTest.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8266670
26+
* @bug 8266670 8291734
2727
* @summary Test expected AccessFlag's on classes.
2828
*/
2929

@@ -46,16 +46,11 @@
4646
* return the Class object created from a module-info.class
4747
* file. Therefore, this test does not attempt to probe the setting of
4848
* that access flag.
49-
*
50-
* For a class, the VM must treat the class as if the ACC_SUPER bit
51-
* were set, but that bit is cleared by HotSpot when it is passed out
52-
* to the core reflection libraries. Therefore, this test does not
53-
* attempt to check whether or not AccessFlag.SUPER is set.
5449
*/
55-
@ExpectedClassFlags("[PUBLIC, FINAL]")
50+
@ExpectedClassFlags("[PUBLIC, FINAL, SUPER]")
5651
public final class ClassAccessFlagTest {
5752
public static void main(String... args) {
58-
// Top-level and axuillary classes; i.e. non-inner classes
53+
// Top-level and auxiliary classes; i.e. non-inner classes
5954
Class<?>[] testClasses = {
6055
ClassAccessFlagTest.class,
6156
TestInterface.class,
@@ -226,7 +221,7 @@ interface StaticTestInterface {}
226221
interface TestInterface {}
227222

228223

229-
@ExpectedClassFlags("[FINAL, ENUM]")
224+
@ExpectedClassFlags("[FINAL, SUPER, ENUM]")
230225
enum TestOuterEnum {
231226
INSTANCE;
232227
}

0 commit comments

Comments
 (0)