-
Bug
-
Resolution: Fixed
-
P2
-
5.0
-
01
-
x86
-
windows_xp
Name: jl125535 Date: 08/30/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b60)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b60, mixed mode, sharing)
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
A DESCRIPTION OF THE PROBLEM :
Javac 1.5 has changed array cloning due to Bug ID 4900415. Primarily this change affects method/ctor resolution and may result in a change of behaviour of a program if migrating from J2SE 1.4 to J2SE 1.5 (sample code provided).
The latest public doc says that the new method resolution algorithm consists of 2 passes (one for backwards compatiblity and the other for varargs/boxing). When taking the first pass the javac should see that array#clone yields "java.lang.Object" not its "real" type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile & Execute the sample code using J2SE 1.4 and J2SE 1.5 SDKs.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd expect to see the message "you gave me an object" in both cases.
ACTUAL -
J2SE 1.4 emits the message "you gave me an object".
J2SE 1.5 emits the message "you gave me an array of ints" (even with the flags "-source 1.4" and "-target 1.4" set at compile time).
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Bug {
public static void main(String[] args){
method(new int[0].clone());
}
// Java 1.5.0+
public static void method(int[] array){
System.out.println("You gave me an array of ints");
}
// Java 1.4.2 and before
public static void method(Object obj){
System.out.println("You gave me an object");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Explicit cast will do the job: method((Object)new int[0].clone())
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 301333)
======================================================================