diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java index e9d64a6ad72..de37229f68f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java @@ -130,6 +130,7 @@ public class Lint values.add(LintCategory.PREVIEW); } values.add(LintCategory.SYNCHRONIZATION); + values.add(LintCategory.INCUBATING); } // Look for specific overrides @@ -215,6 +216,11 @@ public class Lint */ FINALLY("finally"), + /** + * Warn about use of incubating modules. + */ + INCUBATING("incubating"), + /** * Warn about compiler possible lossy conversions. */ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java index 6c4729c217a..6dd4a368f44 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -117,6 +117,7 @@ import com.sun.tools.javac.code.Kinds; import static com.sun.tools.javac.code.Kinds.Kind.ERR; import static com.sun.tools.javac.code.Kinds.Kind.MDL; import static com.sun.tools.javac.code.Kinds.Kind.MTH; +import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.code.Symbol.ModuleResolutionFlags; @@ -134,6 +135,7 @@ public class Modules extends JCTree.Visitor { private static final String ALL_SYSTEM = "ALL-SYSTEM"; private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; + private final Lint lint; private final Log log; private final Names names; private final Symtab syms; @@ -185,6 +187,7 @@ public class Modules extends JCTree.Visitor { protected Modules(Context context) { context.put(Modules.class, this); log = Log.instance(context); + lint = Lint.instance(context); names = Names.instance(context); syms = Symtab.instance(context); attr = Attr.instance(context); @@ -1351,13 +1354,15 @@ public class Modules extends JCTree.Visitor { .forEach(result::add); } - String incubatingModules = filterAlreadyWarnedIncubatorModules(result.stream() - .filter(msym -> msym.resolutionFlags.contains(ModuleResolutionFlags.WARN_INCUBATING)) - .map(msym -> msym.name.toString())) - .collect(Collectors.joining(",")); + if (lint.isEnabled(LintCategory.INCUBATING)) { + String incubatingModules = filterAlreadyWarnedIncubatorModules(result.stream() + .filter(msym -> msym.resolutionFlags.contains(ModuleResolutionFlags.WARN_INCUBATING)) + .map(msym -> msym.name.toString())) + .collect(Collectors.joining(",")); - if (!incubatingModules.isEmpty()) { - log.warning(Warnings.IncubatingModules(incubatingModules)); + if (!incubatingModules.isEmpty()) { + log.warning(Warnings.IncubatingModules(incubatingModules)); + } } allModules = result; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties index d9bd05ba62a..7893d328afa 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties @@ -213,6 +213,9 @@ javac.opt.Xlint.desc.fallthrough=\ javac.opt.Xlint.desc.finally=\ Warn about finally clauses that do not terminate normally. +javac.opt.Xlint.desc.incubating=\ + Warn about use of incubating modules. + javac.opt.Xlint.desc.lossy-conversions=\ Warn about possible lossy conversions in compound assignment. diff --git a/src/jdk.compiler/share/classes/module-info.java b/src/jdk.compiler/share/classes/module-info.java index c8716233c0f..9826b3f576b 100644 --- a/src/jdk.compiler/share/classes/module-info.java +++ b/src/jdk.compiler/share/classes/module-info.java @@ -162,6 +162,7 @@ import javax.tools.StandardLocation; * {@code fallthrough} falling through from one case of a {@code switch} statement to * the next * {@code finally} {@code finally} clauses that do not terminate normally + * {@code incubating} use of incubating modules * {@code lossy-conversions} possible lossy conversions in compound assignment * {@code missing-explicit-ctor} missing explicit constructors in public and protected classes * in exported packages diff --git a/src/jdk.compiler/share/man/javac.1 b/src/jdk.compiler/share/man/javac.1 index 30b260ac648..b8a7fe60af5 100644 --- a/src/jdk.compiler/share/man/javac.1 +++ b/src/jdk.compiler/share/man/javac.1 @@ -725,6 +725,8 @@ a switch statement to the next. \f[V]finally\f[R]: Warns about \f[V]finally\f[R] clauses that do not terminate normally. .IP \[bu] 2 +\f[V]incubating\f[R]: Warns about the use of incubating modules. +.IP \[bu] 2 \f[V]lossy-conversions\f[R]: Warns about possible lossy conversions in compound assignment. .IP \[bu] 2 diff --git a/test/langtools/tools/javac/modules/IncubatingTest.java b/test/langtools/tools/javac/modules/IncubatingTest.java index 23112d4200e..70df2bbe05a 100644 --- a/test/langtools/tools/javac/modules/IncubatingTest.java +++ b/test/langtools/tools/javac/modules/IncubatingTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8171177 + * @bug 8171177 8187591 * @summary Verify that ModuleResolution attribute flags are honored. * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -238,6 +238,16 @@ public class IncubatingTest extends ModuleTestBase { if (!expected.equals(log)) { throw new AssertionError("Unexpected output: " + log); } + + //test disable lint incubating + new JavacTask(tb) + .options("--module-path", classes.toString(), + "-XDrawDiagnostics", + "-Xlint:-incubating", + "-Werror") + .outdir(testModuleClasses) + .files(findJavaFiles(testModuleSrc)) + .run(Expect.SUCCESS); } private void copyJavaBase(Path targetDir) throws IOException {