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

     1 import java.io.*;
     2 import java.util.*;
     4 import sun.misc.*;
     6 /*
     7  * @test /nodynamiccopyright/
     8  * @bug 6873845
     9  * @summary refine access to symbol file
    10  */
    12 public class T6873845 {
    13     public static void main(String... args) throws Exception {
    14         new T6873845().run();
    15     }
    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");
    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;
    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     }
    41     List<String> opts(String... opts) {
    42         return Arrays.asList(opts);
    43     }
    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     }
    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     }
    71     void m1() {
    72         Unsafe.getUnsafe();
    73     }
    75     @SuppressWarnings("sunapi")
    76     void m2() {
    77         Unsafe.getUnsafe();
    78     }
    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 }

mercurial