test/tools/javac/T6873845.java

changeset 377
d9febdd5ae21
child 1521
71f35e4b93a5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/T6873845.java	Fri Aug 21 14:58:21 2009 -0700
     1.3 @@ -0,0 +1,84 @@
     1.4 +import java.io.*;
     1.5 +import java.util.*;
     1.6 +
     1.7 +import sun.misc.*;
     1.8 +
     1.9 +/*
    1.10 + * @test /nodynamiccopyright/
    1.11 + * @bug 6873845
    1.12 + * @summary refine access to symbol file
    1.13 + */
    1.14 +
    1.15 +public class T6873845 {
    1.16 +    public static void main(String... args) throws Exception {
    1.17 +        new T6873845().run();
    1.18 +    }
    1.19 +
    1.20 +    public void run() throws Exception {
    1.21 +        String out = compile(Arrays.asList("-XDrawDiagnostics", "-X"));
    1.22 +        if (out.contains("sunapi"))
    1.23 +            throw new Exception("unexpected output for -X");
    1.24 +
    1.25 +        String warn1 = "T6873845.java:72:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
    1.26 +        String warn2 = "T6873845.java:77:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
    1.27 +        String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline;
    1.28 +        String note2 = "- compiler.note.sunapi.recompile" + newline;
    1.29 +
    1.30 +        test(opts(),
    1.31 +                warn1 + warn2 + "2 warnings" + newline);
    1.32 +        test(opts("-XDenableSunApiLintControl"),
    1.33 +                note1 + note2);
    1.34 +        test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"),
    1.35 +                "");
    1.36 +        test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"),
    1.37 +                warn1 + "1 warning" + newline);
    1.38 +        test(opts("-XDenableSunApiLintControl", "-Xlint:all"),
    1.39 +                warn1 + "1 warning" + newline);
    1.40 +        test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"),
    1.41 +                note1 + note2);
    1.42 +    }
    1.43 +
    1.44 +    List<String> opts(String... opts) {
    1.45 +        return Arrays.asList(opts);
    1.46 +    }
    1.47 +
    1.48 +    void test(List<String> opts, String expect) throws Exception {
    1.49 +        List<String> args = new ArrayList<String>();
    1.50 +        args.addAll(opts);
    1.51 +        args.add("-d");
    1.52 +        args.add(testClasses.getPath());
    1.53 +        args.add(new File(testSrc, "T6873845.java").getPath());
    1.54 +        compile(args); // to verify resource strings exist
    1.55 +        args.add(0, "-XDrawDiagnostics");
    1.56 +        String out = compile(args);
    1.57 +        if (!out.equals(expect))
    1.58 +            throw new Exception("unexpected output from compiler");
    1.59 +    }
    1.60 +
    1.61 +    String compile(List<String> args) throws Exception{
    1.62 +        StringWriter sw = new StringWriter();
    1.63 +        PrintWriter pw = new PrintWriter(sw);
    1.64 +        System.out.println("compile: " + args);
    1.65 +        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
    1.66 +        pw.close();
    1.67 +        String out = sw.toString();
    1.68 +        System.out.println(out);
    1.69 +        if (rc != 0)
    1.70 +            throw new Exception("compilation failed unexpectedly");
    1.71 +        return out;
    1.72 +    }
    1.73 +
    1.74 +    void m1() {
    1.75 +        Unsafe.getUnsafe();
    1.76 +    }
    1.77 +
    1.78 +    @SuppressWarnings("sunapi")
    1.79 +    void m2() {
    1.80 +        Unsafe.getUnsafe();
    1.81 +    }
    1.82 +
    1.83 +    private File testSrc = new File(System.getProperty("test.src", "."));
    1.84 +    private File testClasses = new File(System.getProperty("test.classes", "."));
    1.85 +    private String newline = System.getProperty("line.separator");
    1.86 +}
    1.87 +

mercurial