United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6294589 : javac barfs with a AssertionError when encountering unexpected annotation

Details
Type:
Bug
Submit Date:
2005-07-07
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2005-08-10
Component:
tools
OS:
linux,windows_xp,windows_2000
Sub-Component:
javac
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

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

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.
                                     
2005-07-25
WORK AROUND

N/A
                                     
2005-07-25
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.
                                     
2005-09-30



Hardware and Software, Engineered to Work Together