test/tools/javac/T6873845.java

Fri, 21 Aug 2009 14:58:21 -0700

author
jjg
date
Fri, 21 Aug 2009 14:58:21 -0700
changeset 377
d9febdd5ae21
child 1521
71f35e4b93a5
permissions
-rw-r--r--

6873845: refine access to symbol file
Reviewed-by: darcy

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

mercurial