Skip to content

Commit

Permalink
8187591: -Werror turns incubator module warning to an error
Browse files Browse the repository at this point in the history
Reviewed-by: jlahoda
  • Loading branch information
asotona committed Nov 21, 2023
1 parent 570dffb commit 53eb6f1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected Lint(Context context) {
values.add(LintCategory.PREVIEW);
}
values.add(LintCategory.SYNCHRONIZATION);
values.add(LintCategory.INCUBATING);
}

// Look for specific overrides
Expand Down Expand Up @@ -215,6 +216,11 @@ public enum LintCategory {
*/
FINALLY("finally"),

/**
* Warn about use of incubating modules.
*/
INCUBATING("incubating"),

/**
* Warn about compiler possible lossy conversions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
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;

Expand All @@ -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;
Expand Down Expand Up @@ -185,6 +187,7 @@ public static Modules instance(Context context) {
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);
Expand Down Expand Up @@ -1351,13 +1354,15 @@ private void setupAllModules() {
.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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions src/jdk.compiler/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
* <tr><th scope="row">{@code fallthrough} <td>falling through from one case of a {@code switch} statement to
* the next
* <tr><th scope="row">{@code finally} <td>{@code finally} clauses that do not terminate normally
* <tr><th scope="row">{@code incubating} <td>use of incubating modules
* <tr><th scope="row">{@code lossy-conversions} <td>possible lossy conversions in compound assignment
* <tr><th scope="row">{@code missing-explicit-ctor} <td>missing explicit constructors in public and protected classes
* in exported packages
Expand Down
2 changes: 2 additions & 0 deletions src/jdk.compiler/share/man/javac.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion test/langtools/tools/javac/modules/IncubatingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,6 +238,16 @@ public void testIncubating(Path base) throws Exception {
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 {
Expand Down

1 comment on commit 53eb6f1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.