Bug 11410 - Exception in Java Builder when debug options turned off
Summary: Exception in Java Builder when debug options turned off
Status: RESOLVED 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 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 13852 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-03-14 16:22 EST by Tim Francis CLA
Modified: 2002-05-28 07:34 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Francis CLA 2002-03-14 16:22:57 EST
When running the java builder from a headless 0214 workbench, I enable 
(or disable) the java compiler debug support by the following code:

Hashtable javaOptions=JavaCore.getOptions();
javaOptions.put("org.eclipse.jdt.core.compiler.debug.sourceFile", "do not 
generate"); 
javaOptions.put("org.eclipse.jdt.core.compiler.debug.lineNumber", "do not 
generate");
javaOptions.put("org.eclipse.jdt.core.compiler.debug.localVariable", "do not 
generate");
JavaCore.setOptions(javaOptions);

When I have all three of those options set, I get the following exception in 
the Java builder.  All three of the options work fine in isolation, but they 
fail when used in combination.

java.lang.ArrayIndexOutOfBoundsException: 1800
        at org.eclipse.jdt.internal.compiler.ClassFile.addAttributes
(ClassFile.java:360)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode
(TypeDeclaration.java:603)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode
(TypeDeclaration.java:635)
        at 
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode
(CompilationUnitDeclaration.java:129)
        at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:530)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:332)
        at org.eclipse.jdt.internal.core.newbuilder.AbstractImageBuilder.compile
(AbstractImageBuilder.java:209)
        at org.eclipse.jdt.internal.core.newbuilder.AbstractImageBuilder.compile
(AbstractImageBuilder.java:156)
        at 
org.eclipse.jdt.internal.core.newbuilder.IncrementalImageBuilder.build
(IncrementalImageBuilder.java:102)
        at org.eclipse.jdt.internal.core.newbuilder.JavaBuilder.buildDeltas
(JavaBuilder.java:146)
        at org.eclipse.jdt.internal.core.newbuilder.JavaBuilder.build
(JavaBuilder.java:98)
        at org.eclipse.core.internal.events.BuildManager$2.run
(BuildManager.java:351)
        at org.eclipse.core.internal.runtime.InternalPlatform.run
(InternalPlatform.java:817)
        at org.eclipse.core.runtime.Platform.run(Platform.java:395)
        at org.eclipse.core.internal.events.BuildManager.basicBuild
(BuildManager.java:109)
        at org.eclipse.core.internal.events.BuildManager.basicBuild
(BuildManager.java:174)
        at org.eclipse.core.internal.events.BuildManager.basicBuild
(BuildManager.java:184)
        at org.eclipse.core.internal.events.BuildManager$1.run
(BuildManager.java:133)
        at org.eclipse.core.internal.runtime.InternalPlatform.run
(InternalPlatform.java:817)
        at org.eclipse.core.runtime.Platform.run(Platform.java:395)
        at org.eclipse.core.internal.events.BuildManager.basicBuild
(BuildManager.java:147)
        at org.eclipse.core.internal.events.BuildManager.build
(BuildManager.java:230)
        at org.eclipse.core.internal.resources.Project.build(Project.java:105)
Comment 1 Olivier Thomann CLA 2002-03-14 16:43:25 EST
Would you have a piece of code that could help us to reproduce the problem?
Comment 2 Olivier Thomann CLA 2002-03-14 16:58:11 EST
When no attributes are generated, we can get an ArrayIndexOutOfBoundsException.
// update the number of attributes
contents[attributeOffset++] = (byte) (attributeNumber >> 8);
contents[attributeOffset] = (byte) attributeNumber;

We reach these two lines without checking that we have enough spaces to write 
inside this array.
I suggest:
if (attributeOffset + 2 >= (contentsLength = contents.length)) {
	System.arraycopy(
		contents,
		0,
		(contents = new byte[contentsLength + INCREMENT_SIZE]),
		0,
		contentsLength);
}
// update the number of attributes
contents[attributeOffset++] = (byte) (attributeNumber >> 8);
contents[attributeOffset] = (byte) attributeNumber;

It would be nice to see if this really fixes the problem. But for that we need a 
test case.
Comment 3 Tim Francis CLA 2002-03-14 18:43:13 EST
I don't have a simple testcase, but I will try the proposed fix, and will let 
you know.
Comment 4 Tim Francis CLA 2002-03-15 15:31:40 EST
I do not have a simple testcase.... but I do have a reproducible testcase, and 
after I applied your fix, the problem went away - so in addition to just 
looking right, this fix seems correct.

Thanks for the prompt response!

(One nit, there was a syntax error in your code snippit - this is what works 
for me)
	int contentsLength = contents.length;
	if (attributeOffset + 2 >= contentsLength) {
		System.arraycopy(
			contents,
			0,
			(contents = new byte[contentsLength + INCREMENT_SIZE]),
			0,
			contentsLength);
	}		
Comment 5 Philipe Mulet CLA 2002-03-15 17:48:50 EST
Olivier - please apply the fix to HEAD for M4.
Comment 6 Olivier Thomann CLA 2002-03-15 19:15:40 EST
Thanks for checking the fix. In fact the code snippet I gave worked on my machine, because I put the 
local at the beginning of the method. This will be fixed for M4.
Comment 7 Olivier Thomann CLA 2002-03-15 19:46:17 EST
Fixed and released in HEAD.
Comment 8 Philipe Mulet CLA 2002-04-16 13:25:11 EDT
Olivier - please backport this fix in 1.0 stream as well.
Comment 9 Olivier Thomann CLA 2002-04-16 14:07:52 EDT
Done.
Comment 10 Philipe Mulet CLA 2002-05-28 07:34:37 EDT
*** Bug 13852 has been marked as a duplicate of this bug. ***