23
23
24
24
/**
25
25
* @test
26
- * @bug 8331081
26
+ * @bug 8331081 8349058
27
27
* @summary Verify 'internal proprietary API' diagnostics if --system is configured
28
28
* @library /tools/lib
29
- * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.main
30
- * jdk.compiler/com.sun.tools.javac.jvm jdk.jdeps/com.sun.tools.javap
29
+ * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.file
30
+ * jdk.compiler/com.sun.tools.javac.jvm jdk.compiler/com.sun.tools.javac.main
31
+ * jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap
31
32
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner
32
33
* @run main SystemSunProprietary
33
34
*/
35
+ import com .sun .tools .javac .file .JavacFileManager ;
36
+ import com .sun .tools .javac .util .Context ;
37
+
34
38
import toolbox .JavacTask ;
35
39
import toolbox .Task ;
36
40
import toolbox .Task .Expect ;
41
45
import java .nio .file .Files ;
42
46
import java .nio .file .Path ;
43
47
import java .nio .file .Paths ;
44
- import java .util .Arrays ;
48
+ import java .util .ArrayList ;
49
+ import java .util .Collections ;
45
50
import java .util .List ;
46
51
47
52
public class SystemSunProprietary extends TestRunner {
48
53
49
54
private final ToolBox tb = new ToolBox ();
50
55
56
+ private Path src ;
57
+ private Path classes ;
58
+
51
59
public SystemSunProprietary () {
52
60
super (System .err );
53
61
}
@@ -58,45 +66,14 @@ public static void main(String... args) throws Exception {
58
66
59
67
@ Test
60
68
public void testUnsafe (Path base ) throws IOException {
61
- Path src = base .resolve ("src" );
69
+ src = base .resolve ("src" );
62
70
tb .writeJavaFiles (
63
71
src ,
64
72
"module m { requires jdk.unsupported; }" ,
65
73
"package test; public class Test { sun.misc.Unsafe unsafe; } " );
66
- Path classes = base .resolve ("classes" );
67
- tb .createDirectories (classes );
68
-
69
- List <String > log ;
70
- List <String > expected =
71
- Arrays .asList (
72
- "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe" ,
73
- "1 warning" );
74
74
75
- log =
76
- new JavacTask (tb )
77
- .options ("-XDrawDiagnostics" )
78
- .outdir (classes )
79
- .files (tb .findJavaFiles (src ))
80
- .run (Expect .SUCCESS )
81
- .writeAll ()
82
- .getOutputLines (Task .OutputKind .DIRECT );
83
-
84
- if (!expected .equals (log )) {
85
- throw new AssertionError ("Unexpected output: " + log );
86
- }
87
-
88
- log =
89
- new JavacTask (tb )
90
- .options ("-XDrawDiagnostics" , "--system" , System .getProperty ("java.home" ))
91
- .outdir (classes )
92
- .files (tb .findJavaFiles (src ))
93
- .run (Expect .SUCCESS )
94
- .writeAll ()
95
- .getOutputLines (Task .OutputKind .DIRECT );
96
-
97
- if (!expected .equals (log )) {
98
- throw new AssertionError ("Unexpected output: " + log );
99
- }
75
+ classes = base .resolve ("classes" );
76
+ tb .createDirectories (classes );
100
77
101
78
// Create a valid argument to system that isn't the current java.home
102
79
Path originalSystem = Path .of (System .getProperty ("java.home" ));
@@ -107,17 +84,54 @@ public void testUnsafe(Path base) throws IOException {
107
84
Files .copy (originalSystem .resolve (path ), to );
108
85
}
109
86
110
- log =
87
+ expectSunapi (false );
88
+ expectSunapi (false , "--system" , System .getProperty ("java.home" ));
89
+ expectSunapi (false , "--release" , String .valueOf (Runtime .version ().feature ()));
90
+ expectSunapi (false , "--release" , String .valueOf (Runtime .version ().feature () - 1 ));
91
+ expectSunapi (true , "--release" , String .valueOf (Runtime .version ().feature ()));
92
+ expectSunapi (true , "--release" , String .valueOf (Runtime .version ().feature () - 1 ));
93
+
94
+ // non-default --system arguments disable sunapi, see JDK-8349058
95
+ expectNoSunapi (false , "--system" , system .toString ());
96
+
97
+ // -XDignore.symbol.file disables sunapi diagnostics, see JDK-8349058
98
+ expectNoSunapi (true );
99
+ expectNoSunapi (true , "--system" , System .getProperty ("java.home" ));
100
+ expectNoSunapi (true , "--system" , system .toString ());
101
+ }
102
+
103
+ private void expectSunapi (boolean ignoreSymbolFile , String ... options ) throws IOException {
104
+ expectSunapi (true , ignoreSymbolFile , options );
105
+ }
106
+
107
+ private void expectNoSunapi (boolean ignoreSymbolFile , String ... options ) throws IOException {
108
+ expectSunapi (false , ignoreSymbolFile , options );
109
+ }
110
+
111
+ private void expectSunapi (boolean expectDiagnostic , boolean ignoreSymbolFile , String ... options )
112
+ throws IOException {
113
+ List <String > expected =
114
+ expectDiagnostic
115
+ ? List .of (
116
+ "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe" ,
117
+ "1 warning" )
118
+ : List .of ("" );
119
+ List <String > allOptions = new ArrayList <>();
120
+ allOptions .add ("-XDrawDiagnostics" );
121
+ Collections .addAll (allOptions , options );
122
+ JavacFileManager fm = new JavacFileManager (new Context (), false , null );
123
+ fm .setSymbolFileEnabled (!ignoreSymbolFile );
124
+ List <String > log =
111
125
new JavacTask (tb )
112
- .options ("-XDrawDiagnostics" , "--system" , system .toString ())
126
+ .fileManager (fm )
127
+ .options (allOptions )
113
128
.outdir (classes )
114
129
.files (tb .findJavaFiles (src ))
115
130
.run (Expect .SUCCESS )
116
131
.writeAll ()
117
132
.getOutputLines (Task .OutputKind .DIRECT );
118
-
119
- if (!expected .equals (log )) {
120
- throw new AssertionError ("Unexpected output: " + log );
133
+ if (!log .equals (expected )) {
134
+ throw new AssertionError ("expected: " + expected + "\n actual: " + log + "\n " );
121
135
}
122
136
}
123
137
0 commit comments