JDK-6294589 : javac barfs with a AssertionError when encountering unexpected annotation
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2005-07-07
  • Updated: 2011-02-16
  • Resolved: 2005-08-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b47Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
windows 2000

A DESCRIPTION OF THE PROBLEM :
According to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/SuppressWarnings.html
"""Compilers must ignore any warning names they do not recognize."""

However, javac seems to abort on seeing "unusedLocal"


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try to compile source code below

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expecting a nice .class file and a warning :D
ACTUAL -
error below

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.AssertionError: {unusedLocal}
        at com.sun.tools.javac.tree.TreeMaker$AnnotationBuilder.visitArray(TreeMaker.java:634)
        at com.sun.tools.javac.code.Attribute$Array.accept(Attribute.java:126)
        at com.sun.tools.javac.tree.TreeMaker$AnnotationBuilder.translate(TreeMaker.java:637)
        at com.sun.tools.javac.tree.TreeMaker$AnnotationBuilder.visitCompoundInternal(TreeMaker.java:628)
        at com.sun.tools.javac.tree.TreeMaker$AnnotationBuilder.translate(TreeMaker.java:641)
        at com.sun.tools.javac.tree.TreeMaker.Annotation(TreeMaker.java:649)
        at com.sun.tools.javac.tree.TreeMaker.Annotations(TreeMaker.java:570)
        at com.sun.tools.javac.tree.TreeMaker.VarDef(TreeMaker.java:554)
        at com.sun.tools.javac.comp.Lower.visitIterableForeachLoop(Lower.java:2908)
        at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:2768)
        at com.sun.tools.javac.tree.Tree$ForeachLoop.accept(Tree.java:602)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1895)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:54)
        at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:145)
        at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:2944)
        at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:540)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1895)
        at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:129)
        at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2281)
        at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2200)
        at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1895)
        at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2003)
        at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1895)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1915)
        at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3081)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:496)
        at com.sun.tools.javac.main.Main.compile(Main.java:592)
        at com.sun.tools.javac.main.Main.compile(Main.java:544)
        at com.sun.tools.javac.Main.compile(Main.java:67)
        at com.sun.tools.javac.Main.main(Main.java:52)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

public class Test {
private void testme( boolean check ) {
ArrayList<Integer> aList = new ArrayList<Integer>();

for( @SuppressWarnings("unusedLocal") Integer i : aList ) {
System.out.println( "checking" );
}
}
}

---------- END SOURCE ----------
###@###.### 2005-07-07 09:31:10 GMT

Comments
EVALUATION This was fixed in Mustang b47 and javac accepts the program. Annotations are indeed legal on local variables, so the program is not incorrect.
30-09-2005

WORK AROUND N/A
25-07-2005

EVALUATION The AssertionError is a genuine bug, but the description and surmised reason are incorrect. This is not a problem with an unrecognized @SuppressWarnings name (a valid @SuppressWarnings name will give the same AssertionError.) The problem is that the user has put the annotation in an inappropriate place -- inside a declaration in a statement. Currently, annotations are only permitted on packages, class declarations, method and field declarations. However, the compiler should not crash given this invalid input, and the bug should remain open until that is addressed.
25-07-2005