Community
Participate
Working Groups
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.
Created attachment 154840 [details] Testcase
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.
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).
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.
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.
Created attachment 155263 [details] Proposed fix + regression test
Released for 3.6M5. Regression test added in: org.eclipse.jdt.core.tests.compiler.regression.StackMapAttributeTest#test046
Verified for 3.6M5 using build I20100122-0800.
Verified.