author | hseigel |
Wed, 02 Mar 2016 23:48:41 +0000 | |
changeset 36397 | c487ced7231c |
parent 32337 | c9d3ab9f601c |
permissions | -rw-r--r-- |
15711
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
15711
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
15711
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
4 |
* |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32337 | 7 |
* published by the Free Software Foundation. |
15711
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
8 |
* |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
13 |
* accompanied this code). |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
14 |
* |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
18 |
* |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
21 |
* questions. |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
22 |
*/ |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
23 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
24 |
/* |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
25 |
* @test |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
26 |
* @bug 8005931 |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
27 |
* @summary javac doesn't set ACC_STRICT for classes with package access |
30846 | 28 |
* @modules jdk.jdeps/com.sun.tools.classfile |
15711
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
29 |
* @run main CheckACC_STRICTFlagOnPkgAccessClassTest |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
30 |
*/ |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
31 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
32 |
import java.io.File; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
33 |
import java.io.IOException; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
34 |
import java.net.URI; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
37 |
import java.util.List; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
38 |
import javax.tools.JavaCompiler; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
39 |
import javax.tools.JavaFileObject; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
40 |
import javax.tools.SimpleJavaFileObject; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
41 |
import javax.tools.ToolProvider; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
42 |
import com.sun.source.util.JavacTask; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
43 |
import com.sun.tools.classfile.ClassFile; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
44 |
import com.sun.tools.classfile.ConstantPoolException; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
45 |
import com.sun.tools.classfile.Descriptor; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
46 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
47 |
import com.sun.tools.classfile.Method; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
48 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
49 |
import static com.sun.tools.classfile.AccessFlags.ACC_STRICT; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
50 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
51 |
public class CheckACC_STRICTFlagOnPkgAccessClassTest { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
52 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
53 |
private static final String AssertionErrorMessage = |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
54 |
"All methods should have the ACC_STRICT access flag " + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
55 |
"please check output"; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
56 |
private static final String CompilationErrorMessage = |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
57 |
"Error thrown when compiling the following source:\n"; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
58 |
private static final String offendingMethodErrorMessage = |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
59 |
"Method %s of class %s doesn't have the ACC_STRICT access flag"; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
60 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
61 |
JavaSource source = new JavaSource(); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
62 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
63 |
private List<String> errors = new ArrayList<>(); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
64 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
65 |
public static void main(String[] args) |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
66 |
throws IOException, ConstantPoolException, InvalidDescriptor { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
67 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
68 |
new CheckACC_STRICTFlagOnPkgAccessClassTest().run(comp); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
69 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
70 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
71 |
private void run(JavaCompiler comp) |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
72 |
throws IOException, ConstantPoolException, InvalidDescriptor { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
73 |
compile(comp); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
74 |
check(); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
75 |
if (errors.size() > 0) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
76 |
for (String error: errors) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
77 |
System.err.println(error); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
78 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
79 |
throw new AssertionError(AssertionErrorMessage); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
80 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
81 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
82 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
83 |
private void compile(JavaCompiler comp) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
84 |
JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null, |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
85 |
Arrays.asList(source)); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
86 |
try { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
87 |
if (!ct.call()) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
88 |
throw new AssertionError(CompilationErrorMessage + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
89 |
source.getCharContent(true)); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
90 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
91 |
} catch (Throwable ex) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
92 |
throw new AssertionError(CompilationErrorMessage + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
93 |
source.getCharContent(true)); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
94 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
95 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
96 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
97 |
void check() |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
98 |
throws |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
99 |
IOException, |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
100 |
ConstantPoolException, |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
101 |
Descriptor.InvalidDescriptor { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
102 |
ClassFile classFileToCheck = ClassFile.read(new File("Test.class")); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
103 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
104 |
for (Method method : classFileToCheck.methods) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
105 |
if ((method.access_flags.flags & ACC_STRICT) == 0) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
106 |
errors.add(String.format(offendingMethodErrorMessage, |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
107 |
method.getName(classFileToCheck.constant_pool), |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
108 |
classFileToCheck.getName())); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
109 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
110 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
111 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
112 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
113 |
class JavaSource extends SimpleJavaFileObject { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
114 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
115 |
String source = "strictfp class Test {" + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
116 |
" Test(){}" + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
117 |
" void m(){}" + |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
118 |
"}"; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
119 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
120 |
public JavaSource() { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
121 |
super(URI.create("Test.java"), JavaFileObject.Kind.SOURCE); |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
122 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
123 |
|
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
124 |
@Override |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
125 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
126 |
return source; |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
127 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
128 |
} |
a975ad2bfe35
8005931: javac doesn't set ACC_STRICT for classes with package access
vromero
parents:
diff
changeset
|
129 |
} |