--- old/make/CompileJavaModules.gmk 2016-10-17 14:53:01.066901978 -0700 +++ new/make/CompileJavaModules.gmk 2016-10-17 14:53:01.010899550 -0700 @@ -95,7 +95,7 @@ ################################################################################ java.desktop_ADD_JAVAC_FLAGS := -Xdoclint:all/protected,-reference \ - '-Xdoclint/package:java.*,javax.*' -Xlint:-deprecation,-exports + '-Xdoclint/package:java.*,javax.*' -Xlint:-deprecation,-exports,-removal java.desktop_COPY := .gif .png .wav .txt .xml .css .pf java.desktop_CLEAN := iio-plugin.properties cursors.properties --- old/make/common/SetupJavaCompilers.gmk 2016-10-17 14:53:01.394916202 -0700 +++ new/make/common/SetupJavaCompilers.gmk 2016-10-17 14:53:01.326913253 -0700 @@ -28,11 +28,11 @@ include JavaCompilation.gmk -DISABLE_WARNINGS := -Xlint:all,-deprecation,-unchecked,-rawtypes,-cast,-serial,-dep-ann,-static,-fallthrough,-try,-varargs,-empty,-finally +DISABLE_WARNINGS := -Xlint:all,-deprecation,-removal,-unchecked,-rawtypes,-cast,-serial,-dep-ann,-static,-fallthrough,-try,-varargs,-empty,-finally # If warnings needs to be non-fatal for testing purposes use a command like: # make JAVAC_WARNINGS="-Xlint:all -Xmaxwarns 10000" -JAVAC_WARNINGS := -Xlint:all -Werror +JAVAC_WARNINGS := -Xlint:all,-removal -Werror # The BOOT_JAVAC setup uses the boot jdk compiler to compile the tools # and the interim javac, to be run by the boot jdk. --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java 2016-10-17 14:53:01.762932160 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java 2016-10-17 14:53:01.646927130 -0700 @@ -113,7 +113,7 @@ * Internal compiler flags (no bits in the lower 16). *****************************************/ - /** Flag is set if symbol is deprecated. + /** Flag is set if symbol is deprecated. See also DEPRECATED_REMOVAL. */ public static final int DEPRECATED = 1<<17; @@ -293,6 +293,11 @@ */ public static final long SYSTEM_MODULE = 1L<<53; + /** + * Flag to indicate the given symbol has been deprecated and marked for removal. + */ + public static final long DEPRECATED_REMOVAL = 1L<<54; + /** Modifier masks. */ public static final int @@ -402,7 +407,8 @@ THROWS(Flags.THROWS), LAMBDA_METHOD(Flags.LAMBDA_METHOD), TYPE_TRANSLATED(Flags.TYPE_TRANSLATED), - MODULE(Flags.MODULE); + MODULE(Flags.MODULE), + DEPRECATED_REMOVAL(Flags.DEPRECATED_REMOVAL); Flag(long flag) { this.value = flag; --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java 2016-10-17 14:53:02.206951415 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java 2016-10-17 14:53:02.090946384 -0700 @@ -25,11 +25,13 @@ package com.sun.tools.javac.code; +import java.util.Arrays; import java.util.EnumSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.main.Option; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Options; @@ -81,12 +83,13 @@ } /** - * Returns a new Lint that has the given LintCategory suppressed. + * Returns a new Lint that has the given LintCategorys suppressed. + * @param lc one or more categories to be suppressed */ - public Lint suppress(LintCategory lc) { + public Lint suppress(LintCategory... lc) { Lint l = new Lint(this); - l.values.remove(lc); - l.suppressedValues.add(lc); + l.values.removeAll(Arrays.asList(lc)); + l.suppressedValues.addAll(Arrays.asList(lc)); return l; } @@ -100,12 +103,33 @@ protected Lint(Context context) { // initialize values according to the lint options Options options = Options.instance(context); - values = EnumSet.noneOf(LintCategory.class); - for (Map.Entry e: map.entrySet()) { - if (options.lint(e.getKey())) - values.add(e.getValue()); + + if (options.isSet(Option.XLINT) || options.isSet(Option.XLINT_CUSTOM, "all")) { + // If -Xlint or -Xlint:all is given, enable all categories by default + values = EnumSet.allOf(LintCategory.class); + } else if (options.isSet(Option.XLINT_CUSTOM, "none")) { + // if -Xlint:none is given, disable all categories by default + values = EnumSet.noneOf(LintCategory.class); + } else { + // otherwise, enable on-by-default categories + values = EnumSet.noneOf(LintCategory.class); + + Source source = Source.instance(context); + if (source.compareTo(Source.JDK1_9) >= 0) { + values.add(LintCategory.DEP_ANN); + } + values.add(LintCategory.REMOVAL); } + // Look for specific overrides + for (LintCategory lc : LintCategory.values()) { + if (options.isSet(Option.XLINT_CUSTOM, lc.option)) { + values.add(lc); + } else if (options.isSet(Option.XLINT_CUSTOM, "-" + lc.option)) { + values.remove(lc); + } + } + suppressedValues = EnumSet.noneOf(LintCategory.class); context.put(lintKey, this); @@ -213,6 +237,11 @@ RAW("rawtypes"), /** + * Warn about use of deprecated-for-removal items. + */ + REMOVAL("removal"), + + /** * Warn about Serializable classes that do not provide a serial version ID. */ SERIAL("serial"), --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java 2016-10-17 14:53:02.702972924 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java 2016-10-17 14:53:02.586967894 -0700 @@ -359,6 +359,10 @@ return (flags_field & DEPRECATED) != 0; } + public boolean isDeprecatedForRemoval() { + return (flags_field & DEPRECATED_REMOVAL) != 0; + } + public boolean isDeprecatableViaAnnotation() { switch (getKind()) { case LOCAL_VARIABLE: --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java 2016-10-17 14:53:03.178993566 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java 2016-10-17 14:53:03.062988535 -0700 @@ -340,6 +340,13 @@ && toAnnotate.owner.kind != MTH && types.isSameType(c.type, syms.deprecatedType)) { toAnnotate.flags_field |= Flags.DEPRECATED; + Attribute fr = c.member(names.forRemoval); + if (fr instanceof Attribute.Constant) { + Attribute.Constant v = (Attribute.Constant) fr; + if (v.type == syms.booleanType && ((Integer) v.value) != 0) { + toAnnotate.flags_field |= Flags.DEPRECATED_REMOVAL; + } + } } } --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java 2016-10-17 14:53:03.639013514 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java 2016-10-17 14:53:03.523008483 -0700 @@ -139,11 +139,14 @@ profile = Profile.instance(context); boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION); + boolean verboseRemoval = lint.isEnabled(LintCategory.REMOVAL); boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED); boolean enforceMandatoryWarnings = true; deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated, enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION); + removalHandler = new MandatoryWarningHandler(log, verboseRemoval, + enforceMandatoryWarnings, "removal", LintCategory.REMOVAL); uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); sunApiHandler = new MandatoryWarningHandler(log, false, @@ -185,6 +188,10 @@ */ private MandatoryWarningHandler deprecationHandler; + /** A handler for messages about deprecated-for-removal usage. + */ + private MandatoryWarningHandler removalHandler; + /** A handler for messages about unchecked or unsafe usage. */ private MandatoryWarningHandler uncheckedHandler; @@ -218,8 +225,13 @@ * @param sym The deprecated symbol. */ void warnDeprecated(DiagnosticPosition pos, Symbol sym) { - if (!lint.isSuppressed(LintCategory.DEPRECATION)) + if (sym.isDeprecatedForRemoval()) { + if (!lint.isSuppressed(LintCategory.REMOVAL)) { + removalHandler.report(pos, "has.been.deprecated.for.removal", sym, sym.location()); + } + } else if (!lint.isSuppressed(LintCategory.DEPRECATION)) { deprecationHandler.report(pos, "has.been.deprecated", sym, sym.location()); + } } /** Warn about unchecked operation. @@ -257,6 +269,7 @@ */ public void reportDeferredDiagnostics() { deprecationHandler.reportDeferredDiagnostic(); + removalHandler.reportDeferredDiagnostic(); uncheckedHandler.reportDeferredDiagnostic(); sunApiHandler.reportDeferredDiagnostic(); } @@ -3212,9 +3225,9 @@ } void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) { - if ((s.flags() & DEPRECATED) != 0 && - (other.flags() & DEPRECATED) == 0 && - s.outermostClass() != other.outermostClass()) { + if ( (s.isDeprecatedForRemoval() + || s.isDeprecated() && !other.isDeprecated()) + && s.outermostClass() != other.outermostClass()) { deferredLintHandler.report(new DeferredLintHandler.LintLogger() { @Override public void report() { --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java 2016-10-17 14:53:04.159036064 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java 2016-10-17 14:53:04.039030860 -0700 @@ -103,7 +103,6 @@ private final TypeAnnotations typeAnnotations; private final Types types; private final JCDiagnostic.Factory diags; - private final Source source; private final DeferredLintHandler deferredLintHandler; private final Lint lint; private final TypeEnvs typeEnvs; @@ -131,7 +130,6 @@ typeAnnotations = TypeAnnotations.instance(context); types = Types.instance(context); diags = JCDiagnostic.Factory.instance(context); - source = Source.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); lint = Lint.instance(context); typeEnvs = TypeEnvs.instance(context); @@ -178,6 +176,7 @@ /** Complete entering a class. * @param sym The symbol of the class to be completed. */ + @Override public void complete(Symbol sym) throws CompletionFailure { // Suppress some (recursive) MemberEnter invocations if (!completionEnabled) { @@ -414,7 +413,7 @@ Type attribImportType(JCTree tree, Env env) { Assert.check(completionEnabled); Lint prevLint = chk.setLint(allowDeprecationOnImport ? - lint : lint.suppress(LintCategory.DEPRECATION)); + lint : lint.suppress(LintCategory.DEPRECATION, LintCategory.REMOVAL)); try { // To prevent deep recursion, suppress completion of some // types. @@ -751,12 +750,12 @@ // can attribute the annotation types and then check to see if the // @Deprecated annotation is present. attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); - if (hasDeprecatedAnnotation(tree.mods.annotations)) - sym.flags_field |= DEPRECATED; + handleDeprecatedAnnotation(tree.mods.annotations, sym); chk.checkNonCyclicDecl(tree); } //where: + @Override protected JCExpression clearTypeParams(JCExpression superType) { switch (superType.getTag()) { case TYPEAPPLY: @@ -767,16 +766,29 @@ } /** - * Check if a list of annotations contains a reference to - * java.lang.Deprecated. + * If a list of annotations contains a reference to java.lang.Deprecated, + * set the DEPRECATED flag. + * If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL. **/ - private boolean hasDeprecatedAnnotation(List annotations) { + private void handleDeprecatedAnnotation(List annotations, Symbol sym) { for (List al = annotations; !al.isEmpty(); al = al.tail) { JCAnnotation a = al.head; - if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty()) - return true; + if (a.annotationType.type == syms.deprecatedType) { + sym.flags_field |= Flags.DEPRECATED; + a.args.stream() + .filter(e -> e.hasTag(ASSIGN)) + .map(e -> (JCAssign) e) + .filter(assign -> TreeInfo.name(assign.lhs) == names.forRemoval) + .findFirst() + .ifPresent(assign -> { + JCExpression rhs = TreeInfo.skipParens(assign.rhs); + if (rhs.hasTag(LITERAL) + && Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) { + sym.flags_field |= DEPRECATED_REMOVAL; + } + }); + } } - return false; } @Override --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java 2016-10-17 14:53:04.579054278 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java 2016-10-17 14:53:04.459049074 -0700 @@ -52,8 +52,6 @@ import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; -import com.sun.tools.javac.code.Lint; -import com.sun.tools.javac.code.Source; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.OptionHelper; import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; @@ -85,7 +83,10 @@ log = Log.instance(context); options = Options.instance(context); classLoaderClass = options.get("procloader"); - locations.update(log, Lint.instance(context), FSInfo.instance(context)); + + // Avoid initializing Lint + boolean warn = options.isLintSet("path"); + locations.update(log, warn, FSInfo.instance(context)); // Setting this option is an indication that close() should defer actually closing // the file manager until after a specified period of inactivity. @@ -171,14 +172,6 @@ private long lastUsedTime = System.currentTimeMillis(); protected long deferredCloseTimeout = 0; - protected Source getSource() { - String sourceName = options.get(Option.SOURCE); - Source source = null; - if (sourceName != null) - source = Source.lookup(sourceName); - return (source != null ? source : Source.DEFAULT); - } - protected ClassLoader getClassLoader(URL[] urls) { ClassLoader thisClassLoader = getClass().getClassLoader(); --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java 2016-10-17 14:53:05.027073705 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java 2016-10-17 14:53:04.907068502 -0700 @@ -42,7 +42,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.ProviderNotFoundException; -import java.nio.file.spi.FileSystemProvider; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -63,7 +62,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.zip.ZipFile; import javax.lang.model.SourceVersion; import javax.tools.JavaFileManager; @@ -159,10 +157,9 @@ } } - // could replace Lint by "boolean warn" - void update(Log log, Lint lint, FSInfo fsInfo) { + void update(Log log, boolean warn, FSInfo fsInfo) { this.log = log; - warn = lint.isEnabled(Lint.LintCategory.PATH); + this.warn = warn; this.fsInfo = fsInfo; } --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java 2016-10-17 14:53:05.555096602 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java 2016-10-17 14:53:05.427091051 -0700 @@ -1460,7 +1460,6 @@ ListBuffer proxies = new ListBuffer<>(); for (int i = 0; i v : proxy.values) { + if (v.fst == names.forRemoval && v.snd instanceof Attribute.Constant) { + Attribute.Constant c = (Attribute.Constant) v.snd; + if (c.type == syms.booleanType && ((Integer) c.value) != 0) { + sym.flags_field |= DEPRECATED_REMOVAL; + } + } + } } proxies.append(proxy); --- old/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java 2016-10-17 14:53:06.091119846 -0700 +++ new/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java 2016-10-17 14:53:05.971114642 -0700 @@ -37,6 +37,7 @@ import java.util.EnumSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Locale; import java.util.Map; import java.util.ServiceLoader; @@ -111,7 +112,6 @@ "all", log.localize(PrefixKind.JAVAC, "opt.Xlint.all"))); for (LintCategory lc : LintCategory.values()) { - if (lc.hidden) continue; log.printRawLines(WriterKind.STDOUT, String.format(LINT_KEY_FORMAT, lc.option, @@ -801,8 +801,8 @@ /** The kind of choices for this option, if any. */ private final ChoiceKind choiceKind; - /** The choices for this option, if any, and whether or not the choices are hidden. */ - private final Map choices; + /** The choices for this option, if any. */ + private final Set choices; /** * Looks up the first option matching the given argument in the full set of options. @@ -815,7 +815,8 @@ /** * Looks up the first option matching the given argument within a set of options. - * @param arg the argument to be matches + * @param arg the argument to be matched + * @param options the set of possible options * @return the first option that matches, or null if none. */ public static Option lookup(String arg, Set