11/*
2- * Copyright (c) 2022, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2022, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2222 *
2323 */
2424
25- /**
25+ /*
2626 * @test
2727 * @bug 8291360
2828 * @summary Test getting the class file version for java.lang.Class API
29+ * @library /test/lib
2930 * @modules java.base/java.lang:open
3031 * @compile classFileVersions.jcod
31- * @compile --enable-preview -source ${jdk.version} ClassFileVersionTest.java
3232 * @run main/othervm --enable-preview ClassFileVersionTest
3333 */
3434
35+ import java .lang .classfile .ClassFile ;
36+ import java .lang .constant .ClassDesc ;
3537import java .lang .reflect .*;
3638
39+ import jdk .test .lib .ByteCodeLoader ;
40+
3741public class ClassFileVersionTest {
3842 public static final int LOWER_16 = 0x0000_FFFF ;
39- /*
40- * Include a use of a preview API so that the minor class file
41- * version of the class file for this class gets set during
42- * compilation. If a particular class becomes non-preview, any
43- * currently preview class can be substituted in.
44- */
45- private static final Class <?> PREVIEW_API = java .lang .ScopedValue .class ;
4643 static Method m ;
4744
4845 public static void testIt (String className , int expectedResult ) throws Exception {
@@ -69,8 +66,10 @@ public static void main(String argv[]) throws Throwable {
6966 int latestMajor = ClassFileFormatVersion .latest ().major ();
7067
7168 testIt (Object .class , latestMajor );
72- // ClassFileVersionTest use preview features so its minor version should be 0xFFFF
73- testIt (ClassFileVersionTest .class , (~LOWER_16 ) | latestMajor );
69+
70+ Class <?> previewClass = ByteCodeLoader .load ("PreviewClass" , ClassFile .of ().build (ClassDesc .of ("PreviewClass" ),
71+ clb -> clb .withVersion (ClassFile .latestMajorVersion (), ClassFile .PREVIEW_MINOR_VERSION )));
72+ testIt (previewClass , (~LOWER_16 ) | latestMajor );
7473 testIt ("Version64" , 64 );
7574 testIt ("Version59" , 59 );
7675 testIt ("Version45_3" , 0x0003_002D ); // 3:45
0 commit comments