Annotation-caused compiler crash
Hi,
When attempting to build against a class that uses runtime annotations, javac is crashing with:
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
The test case that generates this error can be found at:
http://www.cjtucker.com/annotation-bug.tgz
Synopsis:
Attempting to build against a class that contains a runtime annotation requires the definition of the annotation to be available to the compiler. If the definition is not available, the compiler crashes.
Test case:
The test case attempts to build three classes in three separate packages: a simple RUNTIME scoped annotation, a "core" class, and a "ui" class that builds against the core class. The "ui" class neither knows nor cares about the annotated properties of the "core" class. The annotation class is build in isolation; the core class is built only against the annotation class; the ui class is built only against the core class.
The test case tarball contains the necessary .java files and directory structure for compilation. The compilation commands are contained in compile.sh.
The crash can be avoided by including the annotation class in the classpath when building the ui component. The crash has been reproduced in 1.5.0_04, 1.5.0_05, and 1.6.0b61. Other JDKs have not been tested. The crash occurs with both RUNTIME and CLASS scoped annotations, though not with SOURCE scope (as expected: the compiler is correctly stripping annotations in that case). The crash does not occur if the annotation does not take parameters (i.e. is an empty "marker" annotation).
This raises some additional questions I'd be interested in hearing comment on. What is the expected behavior here? I would expect the annotation class should *not* be required as a dependency, in the same way I'm not expected to declare a dependency on every class used by a class I interact with. This behavior with annotations seems to breach encapsulation (for example, a client would have to know that my libraries happened to be using a Hibernate persistence layer whether or not this is of interest to them). Perhaps one of the Java gurus here could shed some further light on this?
Cheers,
Chris Tucker

