0N/Aimport java.io.*;
2362N/Aimport java.util.*;
0N/A
0N/Aimport sun.misc.*;
0N/A
0N/A/*
0N/A * @test /nodynamiccopyright/
0N/A * @bug 6873845
0N/A * @summary refine access to symbol file
0N/A */
0N/A
0N/Apublic class T6873845 {
0N/A public static void main(String... args) throws Exception {
0N/A new T6873845().run();
0N/A }
0N/A
0N/A public void run() throws Exception {
0N/A String out = compile(Arrays.asList("-XDrawDiagnostics", "-X"));
2362N/A if (out.contains("sunapi"))
2362N/A throw new Exception("unexpected output for -X");
2362N/A
0N/A String warn1 = "T6873845.java:72:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
0N/A String warn2 = "T6873845.java:77:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline;
0N/A String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline;
0N/A String note2 = "- compiler.note.sunapi.recompile" + newline;
0N/A
0N/A test(opts(),
0N/A warn1 + warn2 + "2 warnings" + newline);
0N/A test(opts("-XDenableSunApiLintControl"),
0N/A note1 + note2);
0N/A test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"),
0N/A "");
0N/A test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"),
0N/A warn1 + "1 warning" + newline);
0N/A test(opts("-XDenableSunApiLintControl", "-Xlint:all"),
0N/A warn1 + "1 warning" + newline);
0N/A test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"),
0N/A note1 + note2);
0N/A }
0N/A
0N/A List<String> opts(String... opts) {
0N/A return Arrays.asList(opts);
0N/A }
0N/A
0N/A void test(List<String> opts, String expect) throws Exception {
0N/A List<String> args = new ArrayList<String>();
0N/A args.addAll(opts);
0N/A args.add("-d");
0N/A args.add(testClasses.getPath());
0N/A args.add(new File(testSrc, "T6873845.java").getPath());
compile(args); // to verify resource strings exist
args.add(0, "-XDrawDiagnostics");
String out = compile(args);
if (!out.equals(expect))
throw new Exception("unexpected output from compiler");
}
String compile(List<String> args) throws Exception{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
System.out.println("compile: " + args);
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
pw.close();
String out = sw.toString();
System.out.println(out);
if (rc != 0)
throw new Exception("compilation failed unexpectedly");
return out;
}
void m1() {
Unsafe.getUnsafe();
}
@SuppressWarnings("sunapi")
void m2() {
Unsafe.getUnsafe();
}
private File testSrc = new File(System.getProperty("test.src", "."));
private File testClasses = new File(System.getProperty("test.classes", "."));
private String newline = System.getProperty("line.separator");
}