1 import java.io.*;
2 import java.util.*;
3 
4 import sun.misc.*;
5 
6 /*
7  * @test /nodynamiccopyright/
8  * @bug 6873845
9  * @summary refine access to symbol file
10  */
11 
12 public class T6873845 {
main(String... args)13     public static void main(String... args) throws Exception {
14         new T6873845().run();
15     }
16 
run()17     public void run() throws Exception {
18         String out = compile(Arrays.asList("-XDrawDiagnostics", "-X"));
19         if (out.contains("sunapi"))
20             throw new Exception("unexpected output for -X");
21 
22         String warn1 = "T6873845.java:73:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
23         String warn2 = "T6873845.java:78:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
24         String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline;
25         String note2 = "- compiler.note.sunapi.recompile" + newline;
26 
27         test(opts(),
28                 warn1 + warn2 + "2 warnings" + newline);
29         test(opts("-XDenableSunApiLintControl"),
30                 note1 + note2);
31         test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"),
32                 "");
33         test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"),
34                 warn1 + "1 warning" + newline);
35         test(opts("-XDenableSunApiLintControl", "-Xlint:all"),
36                 warn1 + "1 warning" + newline);
37         test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"),
38                 note1 + note2);
39     }
40 
opts(String... opts)41     List<String> opts(String... opts) {
42         return Arrays.asList(opts);
43     }
44 
test(List<String> opts, String expect)45     void test(List<String> opts, String expect) throws Exception {
46         List<String> args = new ArrayList<String>();
47         args.addAll(opts);
48         args.add("-d");
49         args.add(testClasses.getPath());
50         args.add(new File(testSrc, "T6873845.java").getPath());
51         compile(args); // to verify resource strings exist
52         args.add(0, "-XDrawDiagnostics");
53         String out = compile(args);
54         if (!out.equals(expect))
55             throw new Exception("unexpected output from compiler; expected: " + expect +
56                     "\n  found: " + out);
57     }
58 
compile(List<String> args)59     String compile(List<String> args) throws Exception{
60         StringWriter sw = new StringWriter();
61         PrintWriter pw = new PrintWriter(sw);
62         System.out.println("compile: " + args);
63         int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
64         pw.close();
65         String out = sw.toString();
66         System.out.println(out);
67         if (rc != 0)
68             throw new Exception("compilation failed unexpectedly");
69         return out;
70     }
71 
m1()72     void m1() {
73         Unsafe.getUnsafe();
74     }
75 
76     @SuppressWarnings("sunapi")
m2()77     void m2() {
78         Unsafe.getUnsafe();
79     }
80 
81     private File testSrc = new File(System.getProperty("test.src", "."));
82     private File testClasses = new File(System.getProperty("test.classes", "."));
83     private String newline = System.getProperty("line.separator");
84 }
85 
86