Community
Participate
Working Groups
One customer had a JAR file that contained 2 .class file One of the .class file is not a valid bytecode .class file (wrong magic number) user does not know the bytecode is not valid. Can we have some error or warning in the navigator (if the JAR is added as library) or in the bytecode editor (if teh .class is opened) ? I will attach teh JAR file. 1) create a Java project 2) add the JAR file in the library tab of the project's properties 3) expand the JAR
Created attachment 5284 [details] JAR file containing 1 wrong bytecode
Asking JDT/Core for comments since they could provide error markers in these cases.
On the second .class file that is actually a zip file (if you renamed it with .zip , you can open it using Winzip), you actually get a ClassFormatException when you try to open it. In the class file editor (line 371), the UI is simply checking that the new class file reader is not null. If it is null, it could report that the corresponding file is not a valid .class file. This is specified on org.eclipse.jdt.core.ToolFactory.createDefaultClassFileReader. /** * Create a classfile reader onto a classfile Java element. * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the file named fileName doesn't represent a valid .class file. * * The decoding flags are described in IClassFileReader. * * @param classfile the classfile element to introspect * @param decodingFlag the flag used to decode the class file reader. * @return a default classfile reader * * @see IClassFileReader */
The class file editor needs to be fixed on the JDT/UI side. We could improve the error reporting of invalid .class file. For now the corresponding type is reported as "cannot be resolved".