JDK-6365854 : javac crashes when compiling against an annotated class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2005-12-21
  • Updated: 2011-02-16
  • Resolved: 2006-02-04
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 b71Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux cannonball 2.6.10 #1 Wed Mar 2 22:37:07 PST 2005 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
javac crashes when compiling against a class that uses annotations if the class defining those annotations is not available on the build path.  Thus:
class A is an annotation class
class B uses an annotation from A
class C uses B
Compiling class C should require that class B be on the build path, but not class A.   However, leaving out class A causes a javac crash.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following classes can be used to reproduce this bug:
import static java.lang.annotation.RetentionPolicy.RUNTIME;

TestAnnotation.java:
package test.annotation;
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
        int test();
}


TestCore.java:
package test.core;

import test.annotation.TestAnnotation;

public class TestCore
{
    @TestAnnotation(test = 1)
    public static void main( String[] args )  { }

    public void test()
    {
        System.out.println("test");
    }
}

TestUi.java
package test.ui;

import test.core.TestCore;

/**
 * Hello world!
 *
 */
public class TestUi
{
    public static void main( String[] args )
    {
        TestCore tc = new TestCore();
        System.out.println(tc.toString());
    }
}


Put these in appropriate package directories, create target directories (annotation, core, ui) and compile using:
javac -d annotation test/annotation/TestAnnotation.java
javac -d core -cp annotation test/core/TestCore.java
javac -d ui -cp core test/ui/TestUi.java

The third command will cause javac to crash

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The third command should correct compile TestUi.java.  Specifically, TestUi.java should not require a binary dependency on TestAnnotation.class (nor does it in other javac implementations, such as that used by Eclipse).
ACTUAL -
The third command crashes with the error.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.5.0_05). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: file test/annotation/TestAnnotation.class not found

An exception has occurred in the compiler (1.6.0-rc). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for test.annotation.TestAnnotation not found

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See "steps to reproduce".
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use a different javac compiler.  Not tenable for distributable builds.

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/langtools_data/mustang/6365854/
29-12-2005

EVALUATION There doesn't seem to be any problems allowing the program to compile without the annotations. After the fix, the compiler will accept the program but issue a warning. The rationale is that the missing annotation can cause problems when running the program.
29-12-2005

EVALUATION The compiler should not crash and this problem will be addressed first. While it is desireable to allow the compilation to continue without the annotation, I will have to investigate if it is allowable. For example, the compiler cannot determine if the missing annotation has the meta-annotation @Inherited. This can cause problems for annotation processors.
23-12-2005

WORK AROUND Include the annotation in the build: javac -d ui -cp core:annotation test/ui/TestUi.java
23-12-2005