1 /* 2 * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /** 26 * @ignore Fix 8328162 27 * @test 28 * @bug 8291360 8293448 29 * @summary Test getting a class's raw access flags using java.lang.Class API 30 * @modules java.base/java.lang:open 31 * @enablePreview 32 * @compile classAccessFlagsRaw.jcod 33 * @run main/othervm ClassAccessFlagsRawTest 34 */ 35 36 import java.lang.reflect.*; 37 38 public class ClassAccessFlagsRawTest { 39 40 static Method m; 41 42 public static void testIt(String className, int expectedResult) throws Exception { 43 Class<?> testClass = Class.forName(className); 44 int flags = (int)m.invoke(testClass); 45 if (flags != expectedResult) { 46 throw new RuntimeException( 47 "expected 0x" + Integer.toHexString(expectedResult) + ", got 0x" + Integer.toHexString(flags) + " for class " + className); 48 } 49 } 50 51 public static void main(String argv[]) throws Throwable { 52 Class<?> cl = java.lang.Class.class; 53 m = cl.getDeclaredMethod("getClassAccessFlagsRaw", new Class[0]); 54 m.setAccessible(true); 55 56 testIt("SUPERset", Modifier.PUBLIC | Modifier.IDENTITY); 57 // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files 58 testIt("SUPERnotset", Modifier.PUBLIC | Modifier.IDENTITY); 59 60 // test primitive array. should return ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC. 61 int flags = (int)m.invoke((new int[3]).getClass()); 62 if (flags != (Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC)) { 63 throw new RuntimeException( 64 "expected 0x411, got 0x" + Integer.toHexString(flags) + " for primitive array"); 65 } 66 67 // test object array. should return flags of component. 68 flags = (int)m.invoke((new SUPERnotset[2]).getClass()); 69 // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files 70 if (flags != (Modifier.PUBLIC | Modifier.IDENTITY)) { 71 throw new RuntimeException( 72 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array"); 73 } 74 75 // test multi-dimensional object array. should return flags of component. 76 flags = (int)m.invoke((new SUPERnotset[4][2]).getClass()); 77 // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files 78 if (flags != (Modifier.PUBLIC | Modifier.IDENTITY)) { 79 throw new RuntimeException( 80 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array"); 81 } 82 } 83 }