test/tools/javac/T6873845.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 1521
71f35e4b93a5
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

     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: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;
    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; expected: " + expect +
    56                     "\n  found: " + out);
    57     }
    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     }
    72     void m1() {
    73         Unsafe.getUnsafe();
    74     }
    76     @SuppressWarnings("sunapi")
    77     void m2() {
    78         Unsafe.getUnsafe();
    79     }
    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 }

mercurial