test/tools/javac/T6873845.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1521
71f35e4b93a5
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial