Bug 298250 - [1.6][compiler] NegativeArraySizeException in StackMapFrame.duplicate
Summary: [1.6][compiler] NegativeArraySizeException in StackMapFrame.duplicate
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.6 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-19 09:45 EST by Chris West (Faux) CLA
Modified: 2010-01-25 14:56 EST (History)
4 users (show)

See Also:


Attachments
Testcase (335 bytes, text/plain)
2009-12-19 09:45 EST, Chris West (Faux) CLA
no flags Details
Stacktrace (6.91 KB, text/plain)
2009-12-19 09:48 EST, Chris West (Faux) CLA
no flags Details
Proposed fix + regression test (4.09 KB, patch)
2010-01-04 14:10 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.