test/tools/javac/T6873845.java

changeset 377
d9febdd5ae21
child 1521
71f35e4b93a5
equal deleted inserted replaced
376:61c1f735df67 377:d9febdd5ae21
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 {
13 public static void main(String... args) throws Exception {
14 new T6873845().run();
15 }
16
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:72:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
23 String warn2 = "T6873845.java:77: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
41 List<String> opts(String... opts) {
42 return Arrays.asList(opts);
43 }
44
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");
56 }
57
58 String compile(List<String> args) throws Exception{
59 StringWriter sw = new StringWriter();
60 PrintWriter pw = new PrintWriter(sw);
61 System.out.println("compile: " + args);
62 int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
63 pw.close();
64 String out = sw.toString();
65 System.out.println(out);
66 if (rc != 0)
67 throw new Exception("compilation failed unexpectedly");
68 return out;
69 }
70
71 void m1() {
72 Unsafe.getUnsafe();
73 }
74
75 @SuppressWarnings("sunapi")
76 void m2() {
77 Unsafe.getUnsafe();
78 }
79
80 private File testSrc = new File(System.getProperty("test.src", "."));
81 private File testClasses = new File(System.getProperty("test.classes", "."));
82 private String newline = System.getProperty("line.separator");
83 }
84

mercurial