Skip to content

Commit

Permalink
8341051: JShell may produce too many preview warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Oct 2, 2024
1 parent 39c17b3 commit 8dee805
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ DiagList getDiagnostics() {
LinkedHashMap<String, Diag> diagMap = new LinkedHashMap<>();
for (Diagnostic<? extends JavaFileObject> in : diagnostics.getDiagnostics()) {
Diag d = diag(in);
if ("compiler.warn.preview.feature.use.plural".equals(d.getCode()) &&
d.getEndPosition() == 0) {
//ignore preview warnings that happen before the snippet:
continue;
}
String uniqueKey = d.getCode() + ":" + d.getPosition() + ":" + d.getMessage(PARSED_LOCALE);
diagMap.put(uniqueKey, d);
}
Expand Down
17 changes: 15 additions & 2 deletions test/langtools/jdk/jshell/ImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8141415 8129418
* @bug 8141415 8129418 8341051
* @summary Test imports
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
Expand Down Expand Up @@ -177,11 +177,24 @@ public void testImportModule() {
assertEval("MethodHandle m;");
}

public void testImportModuleWarnings() {
assertEval("import module java.base;", DiagCheck.DIAG_WARNING, DiagCheck.DIAG_OK);
assertEval("1", DiagCheck.DIAG_OK, DiagCheck.DIAG_OK);
}

@org.testng.annotations.BeforeMethod
public void setUp(Method m) {
switch (m.getName()) {
case "testImportModule" ->
super.setUp(bc -> bc.compilerOptions("--source", System.getProperty("java.specification.version"), "--enable-preview").remoteVMOptions("--enable-preview"));
super.setUp(bc -> bc.compilerOptions("--source", System.getProperty("java.specification.version"),
"--enable-preview")
.remoteVMOptions("--enable-preview"));
case "testImportModuleWarnings" ->
super.setUp(bc -> bc.compilerOptions("--source", System.getProperty("java.specification.version"),
"--enable-preview",
"-Xlint:all",
"-XDforcePreview")
.remoteVMOptions("--enable-preview"));
default ->
super.setUp(bc -> {});
}
Expand Down

0 comments on commit 8dee805

Please sign in to comment.