1 /* 2 * Copyright (c) 2024, 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 * @test 26 * @bug 8331462 27 * @summary [lworld] javac is setting the ACC_STRICT flag for value-based classes 28 * @library /tools/lib 29 * @modules 30 * jdk.compiler/com.sun.tools.javac.code 31 * jdk.compiler/com.sun.tools.javac.util 32 * jdk.compiler/com.sun.tools.javac.api 33 * jdk.compiler/com.sun.tools.javac.file 34 * jdk.compiler/com.sun.tools.javac.main 35 * jdk.jdeps/com.sun.tools.classfile 36 * @build toolbox.ToolBox toolbox.JavacTask 37 * @run main ValueBasedFlagsTest 38 */ 39 40 import java.nio.file.Path; 41 import java.nio.file.Paths; 42 43 import com.sun.tools.javac.code.Flags; 44 import com.sun.tools.javac.util.Assert; 45 import com.sun.tools.classfile.ClassFile; 46 47 import toolbox.TestRunner; 48 import toolbox.ToolBox; 49 import toolbox.JavacTask; 50 import toolbox.Task; 51 52 public class ValueBasedFlagsTest extends TestRunner { 53 ToolBox tb = new ToolBox(); 54 55 public ValueBasedFlagsTest() { 56 super(System.err); 57 } 58 59 protected void runTests() throws Exception { 60 runTests(m -> new Object[] { Paths.get(m.getName()) }); 61 } 62 63 Path[] findJavaFiles(Path... paths) throws Exception { 64 return tb.findJavaFiles(paths); 65 } 66 67 public static void main(String... args) throws Exception { 68 new ValueBasedFlagsTest().runTests(); 69 } 70 71 @Test 72 public void testValueBased(Path base) throws Exception { 73 Path src = base.resolve("src"); 74 tb.writeJavaFiles(src, 75 """ 76 package java.lang; 77 @jdk.internal.ValueBased 78 final class ValueBasedTest {} 79 """); 80 Path classes = base.resolve("classes"); 81 tb.createDirectories(classes); 82 83 new toolbox.JavacTask(tb) 84 .options("--patch-module", "java.base=" + src.toString(), 85 "--enable-preview", "-source", Integer.toString(Runtime.version().feature())) 86 .outdir(classes) 87 .files(findJavaFiles(src)) 88 .run() 89 .writeAll(); 90 Path classFilePath = classes.resolve("java", "lang", "ValueBasedTest.class"); 91 ClassFile classFile = ClassFile.read(classFilePath.toFile()); 92 Assert.check((classFile.access_flags.flags & Flags.ACC_STRICT) == 0); 93 } 94 }