JDK-7198878 : Annotation import not recognized
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-09-17
  • Updated: 2012-09-19
  • Resolved: 2012-09-19
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
C:\jcTest\64_jdk1.7.0_07\bin>javac -version
javac 1.7.0_07

C:\jcTest\64_jdk1.7.0_07\bin>java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
C:\jcTest\64_jdk1.7.0_07\bin>ver
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
I have two source files: Bug.java and BugAnnotation.java. The latter one is located in a jar (by it self) in the classpath and is referenced from Bug.java. When I try to compile Bug.java the following error occurs:

C:\jcTest\64_jdk1.7.0_07\bin>javac -cp BugAnnotation.jar Bug.java
  Bug.java:18: error: cannot find symbol
    @BugAnnotation
     ^
  symbol:   class BugAnnotation
  location: class Bug
1 error



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the given source file with the command javac -cp BugAnnotation.jar Bug.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation is successful
ACTUAL -
See the description

ERROR MESSAGES/STACK TRACES THAT OCCUR :
C:\jcTest\64_jdk1.7.0_07\bin>javac -verbose -g -cp BugAnnotation.jar Bug.java
[parsing started RegularFileObject[Bug.java]]
[parsing completed 24ms]
[search path for source files: BugAnnotation.jar]
[search path for class files: C:\jcTest\64_jdk1.7.0_07\jre\lib\resources.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\rt.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\sunrsasign.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\jsse.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\jce.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\charsets.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\jfr.jar,C:\jcTest\64_jdk1.7.0_07\jre\classes,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\access-bridge-64.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\dnsns.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\jaccess.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\localedata.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\sunec.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\sunjce_provider.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\sunmscapi.jar,C:\jcTest\64_jdk1.7.0_07\jre\lib\ext\zipfs.jar,BugAnnotation.jar]
  Bug.java:18: error: cannot find symbol
    @BugAnnotation
     ^
  symbol:   class BugAnnotation
  location: class Bug
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[BugAnnotation.jar(bug/annotation/BugAnnotation.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Enum.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Comparable.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/io/Serializable.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Retention.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/RetentionPolicy.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Target.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/ElementType.class)]]
[checking test.bug.Bug]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/AutoCloseable.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/CloneNotSupportedException.class)]]
[loading ZipFileIndexFileObject[C:\jcTest\64_jdk1.7.0_07\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]]
[total 436ms]
1 error




REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test.bug;
import test.bug.Bug.Inner.InnerEnum;
import bug.annotation.BugAnnotation;

/**
 * <ol>
 * <li>The annotation needs to be in a jar in the classpath ("local" class path won't trigger the bug)</li>
 * <li>The inner enum needs to be introduced as an import</li>
 * <li>It appears as if the order of the imports plays some role here</li>
 * </ol>
 *
 * @author pbloigu
 *
 */
public class Bug {
    @BugAnnotation
    public static class Inner {
        public static enum InnerEnum {
            VAL1;
        }
    }

    /**
     * This is here only to warrant the import
     *
     * @param enumRef
     */
    public static void reference(InnerEnum enumRef) {
    }
}


package bug.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * @author pbloigu
 *
 */
@Retention(RetentionPolicy.RUNTIME)
public @interface BugAnnotation {

}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Change the order of the imports in Bug.java. However, this is not an option when using Eclipse to automatically sort imports.