JDK-6348499 : javac crashes at com.sun.tools.javac.jvm.ClassReader$BadClassFile
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2005-11-10
  • Updated: 2024-10-07
  • Resolved: 2023-02-14
Related Reports
Relates :  
Relates :  
Description
The javac crashes at "com.sun.tools.javac.jvm.ClassReader$BadClassFile" when trying to handle with the class file that is created by the '(new Filer()).createClassFile()' method.

Pasting the error messages below. Also attached the source code with the bug report.

<Error-MSG>
bash-2.05$ /jdk/sol/b292b/j2sdk1.6.0/bin/javac -J-version
java version "1.6.0-auto"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-304a)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b58, mixed mode)

bash-2.05$ javac -cp /jdk/sol/b304a/j2sdk1.6.0/lib/tools.jar:. -processor simpleAP -processorpath simpleAP.jar -proc:only B.java
@visitType()
B
An exception has occurred in the compiler (1.6.0-auto). 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.jvm.ClassReader$BadClassFile: bad class file: newfile.class
illegal start of class file
Please remove or make sure it appears in the correct subdirectory of the classpath.
	at com.sun.tools.javac.jvm.ClassReader.badClassFile(ClassReader.java:248)
	at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:1367)
	at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1528)
	at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1471)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:370)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:740)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.getAnnotationMirrors(Symbol.java:682)
	at com.sun.tools.javac.model.JavacElements.getAllAnnotationMirrors(JavacElements.java:408)
	at com.sun.tools.javac.model.JavacElements.getAllAnnotationMirrors(JavacElements.java:46)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$ComputeAnnotationSet.scan(JavacProcessingEnvironment.java:477)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:627)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:843)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:629)
	at com.sun.tools.javac.main.Main.compile(Main.java:756)
	at com.sun.tools.javac.main.Main.compile(Main.java:681)
	at com.sun.tools.javac.main.Main.compile(Main.java:670)
	at com.sun.tools.javac.Main.compile(Main.java:70)
	at com.sun.tools.javac.Main.main(Main.java:55)
</Error-MSG>

Comments
Looks like the attachments required to reproduce this bug have been lost somehow. FWIW, javac no longer crashes if it reads an empty class file in 19.0.1. $ cat Test.java public class Test { public Test() { new Empty(); } } $ mkdir classes $ cat /dev/null > classes/Empty.class $ javac -cp classes Test.java Test.java:3: error: cannot access Empty new Empty(); ^ bad class file: classes/Empty.class class file contains wrong class: java.lang.AutoCloseable Please remove or make sure it appears in the correct subdirectory of the classpath. 1 error (The fact that the error message says "class file contains wrong class: java.lang.AutoCloseable" is a separate issue :)
14-02-2023

EVALUATION Short term fix being tracked with 6441871
21-06-2006

SUGGESTED FIX A possible short term fix would be to handle CompletionFailure at the top level and turn it into a friendly error message; not the scary OhMyGod-send-us-a-bug-report message.
05-04-2006

SUGGESTED FIX I think we need to rethink completion errors completely. I have some sketchy ideas: Make javac operate in two modes: 1. completion errors are fatal 2. completion errors are swallowed and errorneous objects are returned instead. Mode 1 should be used for normal batch operation. Mode 2 should be used when in API mode, that is, called from annotation processor or Tree API. If this is confusing, don't worry, we will discuss it in person.
23-02-2006

EVALUATION Dealing with completion errors in JSR 269 in general requires some additional amount of pondering. Currently, completion errors can be thrown from any place in the API. We might not be able to deal with this issue before Mustang beta 2 as we didn't recognize the scope of this problem earlier.
23-02-2006

EVALUATION Note: To run the test program I needed to declare this annotation type: @interface usethis { String value() default ""; } The error that's reported is correct: the processor really does create a bad class file. In round 1 it creates a class file named newfile.class that is completely empty. In round 2 it tries (as it should) to read that empty class file, and fails. The "bad class file" should, however, be reported as an error message rather than as a javac crash.
17-12-2005