Community
Participate
Working Groups
Using 1.5, the following code should compile fine. public class X { public static void main(String argv[]) { int[] tabInt = new int[] {}; int[] tabInt2 = tabInt.clone(); System.out.print("SUCCESS"); } } We report: ---------- 1. ERROR in C:\tests_sources\X.java (at line 5) int[] tabInt2 = tabInt.clone(); ^^^^^^^ Type mismatch: cannot convert from Object to int[] ---------- 1 problem (1 error) The return type of clone() is int[], but inside its signature it is still java.lang.Object. It adds a cast after the clone call.
Array#clone() is answering the array type from compliant mode 1.5 on. Added regression tests: Compliance_1_x#test56 Fixed
fixed
The method descriptor in classfile still returns Object, only the MessageSend resolved type is reflecting the array type.
Regression tests are actually rather: Compliance_1_x#test090 & test091.
There is an issue with following code: public class X { public static void main(String[] arguments) { String[] s = new String[]{"SUCCESS" }; System.out.print(s.length); System.out.print(((String[])s.clone())[0]); } } When changing the resolved type of message send, it optimizes out the need for runtime checkcast, which is still mandated as the runtime #clone() method is only of type Object.
Reused #genericCast slot (renamed into #valueCast) to handle the extra needed cast. Fixed
Verified in 200412140800