< prev index next >

test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -20,13 +20,24 @@
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  /*
-  * @test
+  * @test id=NoPreview
   * @bug 8161013
   * @summary Verify that anonymous class binaries have the correct flags set
+  * @modules java.base/jdk.internal.misc
+  * @run main AnonymousClassFlags
+  */
+ 
+ /*
+  * @test id=Preview
+  * @bug 8161013
+  * @summary Verify that anonymous class binaries have the correct flags set
+  * @modules java.base/jdk.internal.misc
+  * @enablePreview
+  * @compile -XDforcePreview AnonymousClassFlags.java
   * @run main AnonymousClassFlags
   */
  
  import java.util.*;
  import java.nio.file.Path;

@@ -34,53 +45,63 @@
  
  import java.lang.classfile.*;
  import java.lang.classfile.attribute.InnerClassInfo;
  import java.lang.classfile.attribute.InnerClassesAttribute;
  
+ import jdk.internal.misc.PreviewFeatures;
+ 
  public class AnonymousClassFlags {
      public static void main(String[] args) throws Exception {
          new AnonymousClassFlags().test(System.getProperty("test.classes", "."));
      }
  
+     AnonymousClassFlags() {
+         System.currentTimeMillis();
+         super(); // Triggers force preview
+     }
+ 
+     // ACC_SUPER does not exist in InnerClasses before Value Objects
+     private static final int EXPECTED_ACCESS_FLAGS = PreviewFeatures.isEnabled() ? ClassFile.ACC_IDENTITY : 0;
+ 
      /** Maps names of anonymous classes to their expected inner_class_access_flags */
      private static Map<String, Integer> anonClasses = new LinkedHashMap<>();
  
      // ******* TEST CASES ********
  
      static Object o1 = new Object() {
-         { anonClasses.put(getClass().getName(), 0); }
+         { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
      };
  
      static void staticMethod() {
          Object o2 = new Object() {
-             { anonClasses.put(getClass().getName(), 0); }
+             { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
          };
      }
  
      static {
          staticMethod();
  
          Object o3 = new Object() {
-             { anonClasses.put(getClass().getName(), 0); }
+             { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
          };
      }
  
      Object o4 = new Object() {
-         { anonClasses.put(getClass().getName(), 0); }
+         { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
      };
  
      void instanceMethod() {
          Object o5 = new Object() {
-             { anonClasses.put(getClass().getName(), 0); }
+             { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
          };
      }
  
      {
          instanceMethod();
  
          Object o6 = new Object() {
-             { anonClasses.put(getClass().getName(), 0); }
+             { anonClasses.put(getClass().getName(), EXPECTED_ACCESS_FLAGS); }
          };
      }
  
      // ******* TEST IMPLEMENTATION ********
  

@@ -101,11 +122,11 @@
          }
      }
  
      static void assertClassFlags(ClassModel classFile, String name, int expected) {
          int mask = ClassFile.ACC_PUBLIC | ClassFile.ACC_FINAL | ClassFile.ACC_INTERFACE | ClassFile.ACC_ABSTRACT |
-                    ClassFile.ACC_SYNTHETIC | ClassFile.ACC_ANNOTATION | ClassFile.ACC_ENUM;
+                    ClassFile.ACC_SYNTHETIC | ClassFile.ACC_ANNOTATION | ClassFile.ACC_ENUM | ClassFile.ACC_IDENTITY;
          int classExpected = (expected & mask) | ClassFile.ACC_SUPER;
          int classActual = classFile.flags().flagsMask();
          if (classActual != classExpected) {
              throw new AssertionError("Incorrect access_flags for class " + name +
                                       ": expected=" + classExpected + ", actual=" + classActual);
< prev index next >