2
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
27
* @summary javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
28
* @library /tools/lib /test/lib
32
import jdk.test.lib.compiler.CompilerUtils;
33
import toolbox.ToolBox;
35
import java.lang.classfile.ClassFile;
36
import java.lang.classfile.ClassModel;
37
import java.lang.classfile.MethodModel;
38
import java.nio.file.Path;
39
import java.util.ArrayList;
41
import java.io.IOException;
43
public class CheckACC_STRICTFlagOnclinitTest {
44
private static final String AssertionErrorMessage =
45
"All methods should have the ACC_STRICT access flag " +
46
"please check output";
47
private static final String offendingMethodErrorMessage =
48
"Method %s of class %s doesn't have the ACC_STRICT access flag";
50
private static final String SOURCE = """
51
public strictfp class Test {
68
private final List<String> errors = new ArrayList<>();
70
public static void main(String[] args)
72
new CheckACC_STRICTFlagOnclinitTest().run();
77
Path in = Path.of("in");
78
Path out = Path.of("out");
79
ToolBox toolBox = new ToolBox();
80
toolBox.writeJavaFiles(in, SOURCE);
81
CompilerUtils.compile(in, out, "--release", "16");
85
"Test$1Foo$Bar.class",
87
if (!errors.isEmpty()) {
88
for (String error: errors) {
89
System.err.println(error);
91
throw new AssertionError(AssertionErrorMessage);
95
void check(Path dir, String... fileNames) throws IOException {
96
for (String fileName : fileNames) {
97
ClassModel classFileToCheck = ClassFile.of().parse(dir.resolve(fileName));
99
for (MethodModel method : classFileToCheck.methods()) {
100
if ((method.flags().flagsMask() & ClassFile.ACC_STRICT) == 0) {
101
errors.add(String.format(offendingMethodErrorMessage,
102
method.methodName().stringValue(),
103
classFileToCheck.thisClass().asInternalName()));