United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6365854 javac crashes when compiling against an annotated class
JDK-6365854 : javac crashes when compiling against an annotated class

Details
Type:
Bug
Submit Date:
2005-12-21
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2006-02-04
Component:
tools
OS:
linux
Sub-Component:
javac
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

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
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.
                                     
2005-12-23
WORK AROUND

Include the annotation in the build:

javac -d ui -cp core:annotation test/ui/TestUi.java
                                     
2005-12-23
SUGGESTED FIX

http://sa.sfbay.sun.com/projects/langtools_data/mustang/6365854/
                                     
2005-12-29
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.
                                     
2005-12-29



Hardware and Software, Engineered to Work Together