Fri, 21 Aug 2009 14:58:21 -0700
6873845: refine access to symbol file
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Lint.java Fri Aug 21 11:25:45 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Lint.java Fri Aug 21 14:58:21 2009 -0700 1.3 @@ -193,10 +193,20 @@ 1.4 /** 1.5 * Warn about unchecked operations on raw types. 1.6 */ 1.7 - RAW("rawtypes"); 1.8 + RAW("rawtypes"), 1.9 + 1.10 + /** 1.11 + * Warn about Sun proprietary API that may be removed in a future release. 1.12 + */ 1.13 + SUNAPI("sunapi", true); 1.14 1.15 LintCategory(String option) { 1.16 + this(option, false); 1.17 + } 1.18 + 1.19 + LintCategory(String option, boolean hidden) { 1.20 this.option = option; 1.21 + this.hidden = hidden; 1.22 map.put(option, this); 1.23 } 1.24 1.25 @@ -205,6 +215,7 @@ 1.26 } 1.27 1.28 public final String option; 1.29 + public final boolean hidden; 1.30 }; 1.31 1.32 /**
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Aug 21 11:25:45 2009 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Aug 21 14:58:21 2009 -0700 2.3 @@ -119,6 +119,7 @@ 2.4 options.get("-relax") != null); 2.5 useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null; 2.6 allowInvokedynamic = options.get("invokedynamic") != null; 2.7 + enableSunApiLintControl = options.get("enableSunApiLintControl") != null; 2.8 } 2.9 2.10 /** Switch: relax some constraints for retrofit mode. 2.11 @@ -160,6 +161,12 @@ 2.12 */ 2.13 boolean useBeforeDeclarationWarning; 2.14 2.15 + /** 2.16 + * Switch: allow lint infrastructure to control Sun proprietary 2.17 + * API warnings. 2.18 + */ 2.19 + boolean enableSunApiLintControl; 2.20 + 2.21 /** Check kind and type of given tree against protokind and prototype. 2.22 * If check succeeds, store type in tree and return it. 2.23 * If check fails, store errType in tree and return it. 2.24 @@ -2215,8 +2222,12 @@ 2.25 sym.outermostClass() != env.info.scope.owner.outermostClass()) 2.26 chk.warnDeprecated(tree.pos(), sym); 2.27 2.28 - if ((sym.flags() & PROPRIETARY) != 0) 2.29 - log.strictWarning(tree.pos(), "sun.proprietary", sym); 2.30 + if ((sym.flags() & PROPRIETARY) != 0) { 2.31 + if (enableSunApiLintControl) 2.32 + chk.warnSunApi(tree.pos(), "sun.proprietary", sym); 2.33 + else 2.34 + log.strictWarning(tree.pos(), "sun.proprietary", sym); 2.35 + } 2.36 2.37 // Test (3): if symbol is a variable, check that its type and 2.38 // kind are compatible with the prototype and protokind.
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Aug 21 11:25:45 2009 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Aug 21 14:58:21 2009 -0700 3.3 @@ -104,12 +104,15 @@ 3.4 3.5 boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION); 3.6 boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED); 3.7 + boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI); 3.8 boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings(); 3.9 3.10 deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated, 3.11 enforceMandatoryWarnings, "deprecated"); 3.12 uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, 3.13 enforceMandatoryWarnings, "unchecked"); 3.14 + sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi, 3.15 + enforceMandatoryWarnings, "sunapi"); 3.16 } 3.17 3.18 /** Switch: generics enabled? 3.19 @@ -137,6 +140,9 @@ 3.20 */ 3.21 private MandatoryWarningHandler uncheckedHandler; 3.22 3.23 + /** A handler for messages about using Sun proprietary API. 3.24 + */ 3.25 + private MandatoryWarningHandler sunApiHandler; 3.26 3.27 /* ************************************************************************* 3.28 * Errors and Warnings 3.29 @@ -166,12 +172,22 @@ 3.30 uncheckedHandler.report(pos, msg, args); 3.31 } 3.32 3.33 + /** Warn about using Sun proprietary API. 3.34 + * @param pos Position to be used for error reporting. 3.35 + * @param msg A string describing the problem. 3.36 + */ 3.37 + public void warnSunApi(DiagnosticPosition pos, String msg, Object... args) { 3.38 + if (!lint.isSuppressed(LintCategory.SUNAPI)) 3.39 + sunApiHandler.report(pos, msg, args); 3.40 + } 3.41 + 3.42 /** 3.43 * Report any deferred diagnostics. 3.44 */ 3.45 public void reportDeferredDiagnostics() { 3.46 deprecationHandler.reportDeferredDiagnostic(); 3.47 uncheckedHandler.reportDeferredDiagnostic(); 3.48 + sunApiHandler.reportDeferredDiagnostic(); 3.49 } 3.50 3.51
4.1 --- a/src/share/classes/com/sun/tools/javac/main/JavacOption.java Fri Aug 21 11:25:45 2009 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavacOption.java Fri Aug 21 14:58:21 2009 -0700 4.3 @@ -25,11 +25,11 @@ 4.4 4.5 package com.sun.tools.javac.main; 4.6 4.7 +import java.io.PrintWriter; 4.8 +import java.util.LinkedHashMap; 4.9 +import java.util.Map; 4.10 import com.sun.tools.javac.util.Log; 4.11 import com.sun.tools.javac.util.Options; 4.12 -import java.io.PrintWriter; 4.13 -import java.util.Arrays; 4.14 -import java.util.Collection; 4.15 4.16 /** 4.17 * TODO: describe com.sun.tools.javac.main.JavacOption 4.18 @@ -106,9 +106,10 @@ 4.19 */ 4.20 ChoiceKind choiceKind; 4.21 4.22 - /** The choices for this option, if any. 4.23 + /** The choices for this option, if any, and whether or not the choices 4.24 + * are hidden 4.25 */ 4.26 - Collection<String> choices; 4.27 + Map<String,Boolean> choices; 4.28 4.29 Option(OptionName name, String argsNameKey, String descrKey) { 4.30 this.name = name; 4.31 @@ -123,10 +124,18 @@ 4.32 } 4.33 4.34 Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) { 4.35 - this(name, descrKey, choiceKind, Arrays.asList(choices)); 4.36 + this(name, descrKey, choiceKind, createChoices(choices)); 4.37 } 4.38 4.39 - Option(OptionName name, String descrKey, ChoiceKind choiceKind, Collection<String> choices) { 4.40 + private static Map<String,Boolean> createChoices(String... choices) { 4.41 + Map<String,Boolean> map = new LinkedHashMap<String,Boolean>(); 4.42 + for (String c: choices) 4.43 + map.put(c, true); 4.44 + return map; 4.45 + } 4.46 + 4.47 + Option(OptionName name, String descrKey, ChoiceKind choiceKind, 4.48 + Map<String,Boolean> choices) { 4.49 this(name, null, descrKey); 4.50 if (choiceKind == null || choices == null) 4.51 throw new NullPointerException(); 4.52 @@ -153,10 +162,10 @@ 4.53 if (choices != null) { 4.54 String arg = option.substring(name.optionName.length()); 4.55 if (choiceKind == ChoiceKind.ONEOF) 4.56 - return choices.contains(arg); 4.57 + return choices.keySet().contains(arg); 4.58 else { 4.59 for (String a: arg.split(",+")) { 4.60 - if (!choices.contains(a)) 4.61 + if (!choices.keySet().contains(a)) 4.62 return false; 4.63 } 4.64 } 4.65 @@ -181,10 +190,12 @@ 4.66 if (argsNameKey == null) { 4.67 if (choices != null) { 4.68 String sep = "{"; 4.69 - for (String c: choices) { 4.70 - sb.append(sep); 4.71 - sb.append(c); 4.72 - sep = ","; 4.73 + for (Map.Entry<String,Boolean> e: choices.entrySet()) { 4.74 + if (!e.getValue()) { 4.75 + sb.append(sep); 4.76 + sb.append(e.getKey()); 4.77 + sep = ","; 4.78 + } 4.79 } 4.80 sb.append("}"); 4.81 } 4.82 @@ -209,8 +220,8 @@ 4.83 if (choices != null) { 4.84 if (choiceKind == ChoiceKind.ONEOF) { 4.85 // some clients like to see just one of option+choice set 4.86 - for (String c: choices) 4.87 - options.remove(option + c); 4.88 + for (String s: choices.keySet()) 4.89 + options.remove(option + s); 4.90 String opt = option + arg; 4.91 options.put(opt, opt); 4.92 // some clients like to see option (without trailing ":") 4.93 @@ -256,7 +267,7 @@ 4.94 XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) { 4.95 super(name, descrKey, kind, choices); 4.96 } 4.97 - XOption(OptionName name, String descrKey, ChoiceKind kind, Collection<String> choices) { 4.98 + XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) { 4.99 super(name, descrKey, kind, choices); 4.100 } 4.101 @Override
5.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Fri Aug 21 11:25:45 2009 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Fri Aug 21 14:58:21 2009 -0700 5.3 @@ -38,9 +38,9 @@ 5.4 import java.io.File; 5.5 import java.io.FileWriter; 5.6 import java.io.PrintWriter; 5.7 -import java.util.Collection; 5.8 import java.util.EnumSet; 5.9 -import java.util.LinkedHashSet; 5.10 +import java.util.LinkedHashMap; 5.11 +import java.util.Map; 5.12 import java.util.Set; 5.13 import javax.lang.model.SourceVersion; 5.14 5.15 @@ -598,14 +598,14 @@ 5.16 }; 5.17 } 5.18 5.19 - private static Collection<String> getXLintChoices() { 5.20 - Collection<String> choices = new LinkedHashSet<String>(); 5.21 - choices.add("all"); 5.22 + private static Map<String,Boolean> getXLintChoices() { 5.23 + Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>(); 5.24 + choices.put("all", false); 5.25 for (Lint.LintCategory c : Lint.LintCategory.values()) 5.26 - choices.add(c.option); 5.27 + choices.put(c.option, c.hidden); 5.28 for (Lint.LintCategory c : Lint.LintCategory.values()) 5.29 - choices.add("-" + c.option); 5.30 - choices.add("none"); 5.31 + choices.put("-" + c.option, c.hidden); 5.32 + choices.put("none", false); 5.33 return choices; 5.34 } 5.35
6.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Aug 21 11:25:45 2009 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Aug 21 14:58:21 2009 -0700 6.3 @@ -564,12 +564,6 @@ 6.4 compiler.note.deprecated.plural.additional=\ 6.5 Some input files additionally use or override a deprecated API. 6.6 6.7 -# Notes related to annotation processing 6.8 - 6.9 -# Print a client-generated note; assumed to be localized, no translation required 6.10 -compiler.note.proc.messager=\ 6.11 - {0} 6.12 - 6.13 compiler.note.unchecked.filename=\ 6.14 {0} uses unchecked or unsafe operations. 6.15 compiler.note.unchecked.plural=\ 6.16 @@ -584,6 +578,25 @@ 6.17 compiler.note.unchecked.plural.additional=\ 6.18 Some input files additionally use unchecked or unsafe operations. 6.19 6.20 +compiler.note.sunapi.filename=\ 6.21 + {0} uses Sun proprietary API that may be removed in a future release. 6.22 +compiler.note.sunapi.plural=\ 6.23 + Some input files use Sun proprietary API that may be removed in a future release. 6.24 +# The following string may appear after one of the above sunapi messages. 6.25 +compiler.note.sunapi.recompile=\ 6.26 + Recompile with -Xlint:sunapi for details. 6.27 + 6.28 +compiler.note.sunapi.filename.additional=\ 6.29 + {0} uses additional Sun proprietary API that may be removed in a future release. 6.30 +compiler.note.sunapi.plural.additional=\ 6.31 + Some input files additionally use Sun proprietary API that may be removed in a future release. 6.32 + 6.33 +# Notes related to annotation processing 6.34 + 6.35 +# Print a client-generated note; assumed to be localized, no translation required 6.36 +compiler.note.proc.messager=\ 6.37 + {0} 6.38 + 6.39 ##### 6.40 6.41 compiler.misc.count.error=\
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/T6873845.java Fri Aug 21 14:58:21 2009 -0700 7.3 @@ -0,0 +1,84 @@ 7.4 +import java.io.*; 7.5 +import java.util.*; 7.6 + 7.7 +import sun.misc.*; 7.8 + 7.9 +/* 7.10 + * @test /nodynamiccopyright/ 7.11 + * @bug 6873845 7.12 + * @summary refine access to symbol file 7.13 + */ 7.14 + 7.15 +public class T6873845 { 7.16 + public static void main(String... args) throws Exception { 7.17 + new T6873845().run(); 7.18 + } 7.19 + 7.20 + public void run() throws Exception { 7.21 + String out = compile(Arrays.asList("-XDrawDiagnostics", "-X")); 7.22 + if (out.contains("sunapi")) 7.23 + throw new Exception("unexpected output for -X"); 7.24 + 7.25 + String warn1 = "T6873845.java:72:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline; 7.26 + String warn2 = "T6873845.java:77:9: compiler.warn.sun.proprietary: sun.misc.Unsafe" + newline; 7.27 + String note1 = "- compiler.note.sunapi.filename: T6873845.java" + newline; 7.28 + String note2 = "- compiler.note.sunapi.recompile" + newline; 7.29 + 7.30 + test(opts(), 7.31 + warn1 + warn2 + "2 warnings" + newline); 7.32 + test(opts("-XDenableSunApiLintControl"), 7.33 + note1 + note2); 7.34 + test(opts("-XDenableSunApiLintControl", "-XDsuppressNotes"), 7.35 + ""); 7.36 + test(opts("-XDenableSunApiLintControl", "-Xlint:sunapi"), 7.37 + warn1 + "1 warning" + newline); 7.38 + test(opts("-XDenableSunApiLintControl", "-Xlint:all"), 7.39 + warn1 + "1 warning" + newline); 7.40 + test(opts("-XDenableSunApiLintControl", "-Xlint:all,-sunapi"), 7.41 + note1 + note2); 7.42 + } 7.43 + 7.44 + List<String> opts(String... opts) { 7.45 + return Arrays.asList(opts); 7.46 + } 7.47 + 7.48 + void test(List<String> opts, String expect) throws Exception { 7.49 + List<String> args = new ArrayList<String>(); 7.50 + args.addAll(opts); 7.51 + args.add("-d"); 7.52 + args.add(testClasses.getPath()); 7.53 + args.add(new File(testSrc, "T6873845.java").getPath()); 7.54 + compile(args); // to verify resource strings exist 7.55 + args.add(0, "-XDrawDiagnostics"); 7.56 + String out = compile(args); 7.57 + if (!out.equals(expect)) 7.58 + throw new Exception("unexpected output from compiler"); 7.59 + } 7.60 + 7.61 + String compile(List<String> args) throws Exception{ 7.62 + StringWriter sw = new StringWriter(); 7.63 + PrintWriter pw = new PrintWriter(sw); 7.64 + System.out.println("compile: " + args); 7.65 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); 7.66 + pw.close(); 7.67 + String out = sw.toString(); 7.68 + System.out.println(out); 7.69 + if (rc != 0) 7.70 + throw new Exception("compilation failed unexpectedly"); 7.71 + return out; 7.72 + } 7.73 + 7.74 + void m1() { 7.75 + Unsafe.getUnsafe(); 7.76 + } 7.77 + 7.78 + @SuppressWarnings("sunapi") 7.79 + void m2() { 7.80 + Unsafe.getUnsafe(); 7.81 + } 7.82 + 7.83 + private File testSrc = new File(System.getProperty("test.src", ".")); 7.84 + private File testClasses = new File(System.getProperty("test.classes", ".")); 7.85 + private String newline = System.getProperty("line.separator"); 7.86 +} 7.87 +