mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-15 13:49:42 +02:00
8365314: javac fails with an exception for erroneous source
Reviewed-by: vromero
This commit is contained in:
parent
c22e01d776
commit
a6be228642
2 changed files with 34 additions and 9 deletions
|
@ -528,14 +528,15 @@ public class Lint {
|
|||
// Given a @SuppressWarnings annotation, extract the recognized suppressions
|
||||
private EnumSet<LintCategory> suppressionsFrom(Attribute.Compound suppressWarnings) {
|
||||
EnumSet<LintCategory> result = LintCategory.newEmptySet();
|
||||
Attribute.Array values = (Attribute.Array)suppressWarnings.member(names.value);
|
||||
for (Attribute value : values.values) {
|
||||
Optional.of(value)
|
||||
.filter(val -> val instanceof Attribute.Constant)
|
||||
.map(val -> (String) ((Attribute.Constant) val).value)
|
||||
.flatMap(LintCategory::get)
|
||||
.filter(lc -> lc.annotationSuppression)
|
||||
.ifPresent(result::add);
|
||||
if (suppressWarnings.member(names.value) instanceof Attribute.Array values) {
|
||||
for (Attribute value : values.values) {
|
||||
Optional.of(value)
|
||||
.filter(val -> val instanceof Attribute.Constant)
|
||||
.map(val -> (String) ((Attribute.Constant) val).value)
|
||||
.flatMap(LintCategory::get)
|
||||
.filter(lc -> lc.annotationSuppression)
|
||||
.ifPresent(result::add);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8270139 8361445
|
||||
* @bug 8270139 8361445 8365314
|
||||
* @summary Verify error recovery w.r.t. annotations
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
|
@ -224,4 +224,28 @@ public class AnnotationRecovery extends TestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
@Test //JDK-8365314
|
||||
public void testSuppressWarningsMissingAttribute() throws Exception {
|
||||
String code = """
|
||||
@SuppressWarnings
|
||||
public class Test {
|
||||
}
|
||||
""";
|
||||
Path curPath = Path.of(".");
|
||||
List<String> actual = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics", "-XDdev")
|
||||
.sources(code)
|
||||
.outdir(curPath)
|
||||
.run(Expect.FAIL)
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = List.of(
|
||||
"Test.java:1:1: compiler.err.annotation.missing.default.value: java.lang.SuppressWarnings, value",
|
||||
"1 error"
|
||||
);
|
||||
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
error("Expected: " + expected + ", but got: " + actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue