Community
Participate
Working Groups
We have a tool built on Eclipse that calculates the minimum required set of classes necessary to support a list of root classes. Our tool is failing due to what appears to be an incorrect ClassFormatException when creating a ClassFileReader on a class in the Gnome Twain library (found at http://www.gnome.sk/products_jtp_try&buy.html). In our tool, we do the following: IClassFile classFile = getClassFile(type); IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.ALL_BUT_METHOD_BODIES); We get back a null ClassFileReader on the class "SK.gnome.twain.TwainManager". After some debugging with the following code: File file = new File("c:/temp/gnometwain/SK/gnome/twain/TwainManager.class"); if (file.exists()) { FileInputStream fis = new FileInputStream(file); byte[] bytes = new byte[(int) file.length()]; fis.read(bytes); fis.close(); try { ClassFileReader classReader = new ClassFileReader(bytes, org.eclipse.jdt.core.util.IClassFileReader.ALL_BUT_METHOD_BODIES); } catch (Exception e) { e.printStackTrace(); } } It appears that the MethodInfo constructor is failing with a NullPointerException or an IndexOutOfRangeException on line 99 (in the 2.0 final code). On line 67, the attribute count is set to 1. Unfortunately, the attributes variable is never changed from its default value of ClassFileAttribute.NO_ATTRIBUTES causing an exception. We have a work-around for this problem for the time being, but would appreciate it if someone could download this package as a testcase and fix the problem.
Should fix asap, for 2.0.1.
I think I have a fix for it. The problem comes from the fact that this class contains native or abstract methods with an exception attribute. In this case the code in MethodInfo: this.attributesCount = u2At(classFileBytes, 6, offset); this.attributes = ClassFileAttribute.NO_ATTRIBUTES; if (this.attributesCount != 0) { if (no_code_attribute) { if (this.attributesCount != 1) { this.attributes = new IClassFileAttribute[this.attributesCount - 1]; } } else { this.attributes = new IClassFileAttribute[this.attributesCount]; } } has to be replaced with: this.attributesCount = u2At(classFileBytes, 6, offset); this.attributes = ClassFileAttribute.NO_ATTRIBUTES; if (this.attributesCount != 0) { if (no_code_attribute && !isAbstract() && !isNative()) { if (this.attributesCount != 1) { this.attributes = new IClassFileAttribute[this.attributesCount - 1]; } } else { this.attributes = new IClassFileAttribute[this.attributesCount]; } } Then it should work fine. I am waiting for the TwainManager.class file in order to validate this fix.
I can verify that this library provides native methods to access Win32 TWAIN imaging library.
Released in 2.0.1 and 2.1 streams. I will verify it as soon as I got the TwainManager.class file.
Verified.