Community
Participate
Working Groups
Executing the following code results in java.lang.VerifyError: (class: test/cheetah/ForEachTest, method: test signature: ()V) Expecting to find array of objects or arrays on stack cheetah from CVS as of June 23, 8:20pm EDT. Sun JDK 1.5 beta2. ========================================= package test.cheetah; public class ForEachTest { Object[] array = { }; void test() { for (Object object : array) { String str = object.toString(); } } public static void main(String[] args) { new ForEachTest().test(); } } =========================================
I cannot reproduce with HEAD contents.
Closing as WORKSFORME. Please reopen if you still get it with a new cheetah drop.
You meant "latest from JDK_1_5 branch", right? I can reproduce this problem with the latest from JDK_1_5 branch and with both SUN 1.5 beta2 and b57. See bug 68133 for the description of my environment.
Created attachment 12875 [details] ForEachTest.class
I will continue to investigate.
If I run it using the command line, it works fine. If I do it in self-hosting, it fails. I will investigate this issue.
The bug occurs if I have -perserveAllLocals on the command line. If I don't, it works fine.
The problem comes from the fact that str and the secret local variable are sharing the same spot. // Method descriptor #8 ()V // Stack: 2, Locals: 5 void test(); 0 aload_0 1 getfield #13 <Field ForEachTest.array [Ljava/lang/Object;> 4 astore 4 <==== Index 4 for the array local variable. 6 iconst_0 7 istore_2 8 aload 4 10 arraylength 11 istore_3 12 goto 37 15 aload 4 17 iload_2 18 aaload 19 astore_1 20 aload_1 21 invokevirtual #22 <Method java/lang/Object.toString()Ljava/lang/String;> 24 astore 4 26 getstatic #28 <Field java/lang/System.out Ljava/io/PrintStream;> 29 aload 4 31 invokevirtual #34 <Method java/io/PrintStream.println(Ljava/lang/String;)V> 34 iinc 2 1 37 iload_2 38 iload_3 39 if_icmplt 15 42 return Line numbers: [pc: 0, line: 5] [pc: 20, line: 6] [pc: 26, line: 7] [pc: 34, line: 5] [pc: 42, line: 9] Local variable table: [pc: 0, pc: 43] local: this index: 0 type: LForEachTest; [pc: 20, pc: 42] local: object index: 1 type: Ljava/lang/Object; [pc: 26, pc: 34] local: str index: 4 type: Ljava/lang/String; <=== index 4 for str I need to check how this spot can be shared.
#array secret variable was incorrectly inserted after the block had been resolved, and thus was (incorrectly) assumed to be shareable. Added regression test: ForeachStatementTest#test026.