Community
Participate
Working Groups
Consider the following Java snippet: public class Test { public static void use(Object[] x) { } public static void main(String[] args) { Object[] x = null; use(x); } } The Java bytecode produced for main() by the Eclipse 3.7 compiler looks like this: public static void main(java.lang.String[]); Code: 0: aconst_null 1: checkcast #20; //class "[Ljava/lang/Object;" 4: astore_1 5: aload_1 6: invokestatic #21; //Method use:([Ljava/lang/Object;)V 9: return On the contrary, this is the bytecode produced by the OpenJDK 1.6.0b22 compiler: public static void main(java.lang.String[]); Code: 0: aconst_null 1: astore_1 2: aload_1 3: invokestatic #2; //Method use:([Ljava/lang/Object;)V 6: return Note that the Eclipse compiler issues an extra checkcast opcode. It also seems to do that only for arrays and not for any other variable type.
This is a consequence of bug 26903. It looks like this is no longer an issue. Srikanth, please follow up. All references need to be updated.
See also bug 51300
(In reply to comment #1) > This is a consequence of bug 26903. It looks like this is no longer an issue. > Srikanth, please follow up. All references need to be updated. Looks like bug 26903 + bug 51300 modified only: ArrayReference, SingleNameReference, LocalDeclaration. Testing after backing out the change in progress.
(In reply to comment #3) > (In reply to comment #1) > > This is a consequence of bug 26903. It looks like this is no longer an issue. > > Srikanth, please follow up. All references need to be updated. > > Looks like bug 26903 + bug 51300 modified only: > > ArrayReference, SingleNameReference, LocalDeclaration. > > Testing after backing out the change in progress. All tests pass. I also verified that the code generated for the test case attached to this bug and bug 26903 and bug 51300 verify alright and run alright with JDK5,6,7. Released for 3.8 M3 via commit id 237f280b16d1b493931020623a0e18d446c4fadf
Srikanth, after this fix I now get this error with 1.4 VM - java.lang.VerifyError: (class: A, method: main signature: ([Ljava/lang/String;)V) Incompatible types for storing into array of arrays or objects class A { public static void main(String[] args) { try { int[][] tab = (int[][]) null; tab[0] = new int[1]; } catch (NullPointerException e) { System.out.print("OK"); } } } I tried with 1.4 because bug 26903 mentioned that javac 1.4 has a checkcast to make such a program run. Now we just omit that checkcast. OTOH, even javac7 still generates a checkcast for the above class. Perhaps there's something here?
(In reply to comment #5) > Srikanth, after this fix I now get this error with 1.4 VM - > java.lang.VerifyError: (class: A, method: main signature: > ([Ljava/lang/String;)V) Incompatible types for storing into array of arrays or > objects That's bad, thanks for catching it, I'll roll back the fix for M3 and take a look at it in leisure.
Created attachment 205874 [details] Patch to roll back fix & tests Ayush, please release and tag. I am unable to push to upstream. (Auth failures and timeouts)
Created attachment 205875 [details] proposed fix (to be applied on HEAD after the earlier changes have been reverted). Basically, we dont need a checkcast for int[][] aray = null; but do need it for int[][] aray = (int[][])null; to satisfy 1.4 VM
(In reply to comment #7) > Created attachment 205874 [details] [diff] > Patch to roll back fix & tests > > Ayush, please release and tag. I am unable to push to upstream. (Auth failures > and timeouts) Released via commit 4fdb8fd78fd76e33e8dba33f80633397bdb28e98
I verified with build id: I20111025-1800, that the problem reported in comment#6 does not show up anymore i.e the roll back is effective and there are no issues.
Srikanth, patch in comment 8 needs to be reviewed. Thanks.
(In reply to comment #11) > Srikanth, patch in comment 8 needs to be reviewed. Thanks. Patch looks good, Thanks Ayush. Could you please restore the test from the previous patch that was rolled back. The test is testing comment# 0 case and is still a valid test for the limited fix made by the current patch.
Created attachment 206766 [details] proposed fix + regression tests restored the test from rolled back patch and added another test for the Object[] o = (Object[])null case, to verify generated bytecode contains checkcast
Released in HEAD via commit 9eac203f2453ab21a49dee5eceed3025656c3aee
Verified for 3.8M4 with build I20111202-0800.