Bug 21778 - ClassFileReader fails on Gnome Twain class
Summary: ClassFileReader fails on Gnome Twain class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-22 15:06 EDT by Craig Setera CLA
Modified: 2002-07-23 13:42 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Setera CLA 2002-07-22 15:06:24 EDT
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.
Comment 1 Philipe Mulet CLA 2002-07-23 06:43:24 EDT
Should fix asap, for 2.0.1.
Comment 2 Olivier Thomann CLA 2002-07-23 11:56:06 EDT
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.
Comment 3 Craig Setera CLA 2002-07-23 12:07:39 EDT
I can verify that this library provides native methods to access Win32 TWAIN
imaging library.
Comment 4 Olivier Thomann CLA 2002-07-23 12:50:37 EDT
Released in 2.0.1 and 2.1 streams. I will verify it as soon as I got the
TwainManager.class file.
Comment 5 Olivier Thomann CLA 2002-07-23 13:42:26 EDT
Verified.