Bug 298250

Summary: [1.6][compiler] NegativeArraySizeException in StackMapFrame.duplicate
Product: [Eclipse Project] JDT Reporter: Chris West (Faux) <eclipse>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann, ralf, srikanth_sankaran
Version: 3.6   
Target Milestone: 3.6 M5   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Testcase
none
Stacktrace
none
Proposed fix + regression test none

Description Chris West (Faux) CLA 2009-12-19 09:45:00 EST
Build Identifier: I20091210-1301

Attempting to compile the attached testcase, which conditionally throws a non-static inner-class Exception from an anonymous inner class, i.e. via. saving + auto-compile gives:

Error in JDT Core during AST creation
java.lang.NegativeArraySizeException
	at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.duplicate(StackMapFrame.java:127)
	at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7364)
...


Reproducible: Always

Steps to Reproduce:
1. Paste the attached testcase into a Java editor.
2. Comment out the "static" (line 3).
3. Trigger a build, i.e. by saving.
Comment 1 Chris West (Faux) CLA 2009-12-19 09:45:52 EST
Created attachment 154840 [details]
Testcase
Comment 2 Chris West (Faux) CLA 2009-12-19 09:48:09 EST
Created attachment 154841 [details]
Stacktrace

Full stack-trace from the UI.  An additional log entry is generated with just the java.lang.NegativeArraySizeException in, but it's the same.
Comment 3 Olivier Thomann CLA 2010-01-04 10:21:40 EST
This is an invalid code that we don't reject properly.
We should not try to generate the code for the method doThings().

This error should prevent the code from being generated for the enclosing method.

----------
3. ERROR in D:\tests_sources\X.java (at line 11)
	throw new DomainException();
	      ^^^^^^^^^^^^^^^^^^^^^
No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).
Comment 4 Olivier Thomann CLA 2010-01-04 10:23:32 EST
The exception constructor cannot be referenced in a static context without an enclosing instance. I'll investigate why the code is generated with an error.
Comment 5 Olivier Thomann CLA 2010-01-04 11:02:10 EST
The problem comes from the way the compilation is aborted while generating the anonymous type.
The error is reported against the allocation expression for the exception and the outer most method is tagged as having error, but the inner method is not tagged as having error. Therefore the code generation continues till it fails.
We should just make sure we can duplicate stack frames.
Comment 6 Olivier Thomann CLA 2010-01-04 14:10:28 EST
Created attachment 155263 [details]
Proposed fix + regression test
Comment 7 Olivier Thomann CLA 2010-01-04 14:31:12 EST
Released for 3.6M5.
Regression test added in:
org.eclipse.jdt.core.tests.compiler.regression.StackMapAttributeTest#test046
Comment 8 Ayushman Jain CLA 2010-01-25 07:02:44 EST
Verified for 3.6M5 using build I20100122-0800.
Comment 9 Olivier Thomann CLA 2010-01-25 14:56:50 EST
Verified.