JDK-5094318 : REGRESSION: Array cloning is not backwards compatible
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-30
  • Updated: 2017-05-16
  • Resolved: 2004-09-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u1 01Fixed
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.5.0_01 mustang FIXED IN: 1.5.0_01 INTEGRATED IN: 1.5.0_01
26-09-2004

SUGGESTED FIX In code.Symtab: let the definition of arrayCloneMethod depend on -target. ###@###.### 2004-08-30
30-08-2004

EVALUATION A bug. ###@###.### 2004-08-30
30-08-2004