2323
2424/**
2525 * @test
26- * @bug 8331081
26+ * @bug 8331081 8349058
2727 * @summary Verify 'internal proprietary API' diagnostics if --system is configured
2828 * @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
3132 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner
3233 * @run main SystemSunProprietary
3334 */
35+ import com .sun .tools .javac .file .JavacFileManager ;
36+ import com .sun .tools .javac .util .Context ;
37+
3438import toolbox .JavacTask ;
3539import toolbox .Task ;
3640import toolbox .Task .Expect ;
4145import java .nio .file .Files ;
4246import java .nio .file .Path ;
4347import java .nio .file .Paths ;
44- import java .util .Arrays ;
48+ import java .util .ArrayList ;
49+ import java .util .Collections ;
4550import java .util .List ;
4651
4752public class SystemSunProprietary extends TestRunner {
4853
4954 private final ToolBox tb = new ToolBox ();
5055
56+ private Path src ;
57+ private Path classes ;
58+
5159 public SystemSunProprietary () {
5260 super (System .err );
5361 }
@@ -58,45 +66,14 @@ public static void main(String... args) throws Exception {
5866
5967 @ Test
6068 public void testUnsafe (Path base ) throws IOException {
61- Path src = base .resolve ("src" );
69+ src = base .resolve ("src" );
6270 tb .writeJavaFiles (
6371 src ,
6472 "module m { requires jdk.unsupported; }" ,
6573 "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" );
7474
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 );
10077
10178 // Create a valid argument to system that isn't the current java.home
10279 Path originalSystem = Path .of (System .getProperty ("java.home" ));
@@ -107,17 +84,54 @@ public void testUnsafe(Path base) throws IOException {
10784 Files .copy (originalSystem .resolve (path ), to );
10885 }
10986
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 =
111125 new JavacTask (tb )
112- .options ("-XDrawDiagnostics" , "--system" , system .toString ())
126+ .fileManager (fm )
127+ .options (allOptions )
113128 .outdir (classes )
114129 .files (tb .findJavaFiles (src ))
115130 .run (Expect .SUCCESS )
116131 .writeAll ()
117132 .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 " );
121135 }
122136 }
123137
0 commit comments