File tree Expand file tree Collapse file tree 2 files changed +34
-9
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/code
test/langtools/tools/javac/recovery Expand file tree Collapse file tree 2 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -528,14 +528,15 @@ private EnumSet<LintCategory> suppressionsFrom(Stream<Attribute.Compound> attrib
528528 // Given a @SuppressWarnings annotation, extract the recognized suppressions
529529 private EnumSet <LintCategory > suppressionsFrom (Attribute .Compound suppressWarnings ) {
530530 EnumSet <LintCategory > result = LintCategory .newEmptySet ();
531- Attribute .Array values = (Attribute .Array )suppressWarnings .member (names .value );
532- for (Attribute value : values .values ) {
533- Optional .of (value )
534- .filter (val -> val instanceof Attribute .Constant )
535- .map (val -> (String ) ((Attribute .Constant ) val ).value )
536- .flatMap (LintCategory ::get )
537- .filter (lc -> lc .annotationSuppression )
538- .ifPresent (result ::add );
531+ if (suppressWarnings .member (names .value ) instanceof Attribute .Array values ) {
532+ for (Attribute value : values .values ) {
533+ Optional .of (value )
534+ .filter (val -> val instanceof Attribute .Constant )
535+ .map (val -> (String ) ((Attribute .Constant ) val ).value )
536+ .flatMap (LintCategory ::get )
537+ .filter (lc -> lc .annotationSuppression )
538+ .ifPresent (result ::add );
539+ }
539540 }
540541 return result ;
541542 }
Original file line number Diff line number Diff line change 2323
2424/*
2525 * @test
26- * @bug 8270139 8361445
26+ * @bug 8270139 8361445 8365314
2727 * @summary Verify error recovery w.r.t. annotations
2828 * @library /tools/lib
2929 * @modules jdk.compiler/com.sun.tools.javac.api
@@ -224,4 +224,28 @@ enum E {
224224 }
225225 }
226226
227+ @ Test //JDK-8365314
228+ public void testSuppressWarningsMissingAttribute () throws Exception {
229+ String code = """
230+ @SuppressWarnings
231+ public class Test {
232+ }
233+ """ ;
234+ Path curPath = Path .of ("." );
235+ List <String > actual = new JavacTask (tb )
236+ .options ("-XDrawDiagnostics" , "-XDdev" )
237+ .sources (code )
238+ .outdir (curPath )
239+ .run (Expect .FAIL )
240+ .getOutputLines (OutputKind .DIRECT );
241+
242+ List <String > expected = List .of (
243+ "Test.java:1:1: compiler.err.annotation.missing.default.value: java.lang.SuppressWarnings, value" ,
244+ "1 error"
245+ );
246+
247+ if (!Objects .equals (actual , expected )) {
248+ error ("Expected: " + expected + ", but got: " + actual );
249+ }
250+ }
227251}
You can’t perform that action at this time.
0 commit comments