JDK-6359106 : Valid generics code does not compile
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_xp
  • CPU: x86
  • Submitted: 2005-12-05
  • Updated: 2011-02-16
  • Resolved: 2006-02-04
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 JDK 6
5.0u10Fixed 6 b71Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


A DESCRIPTION OF THE PROBLEM :
Valid generics code does not compile under certain conditions

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the code given.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile
ACTUAL -
The code does not compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
tests/CompileTest2.java:26: <R,W>test(java.util.Collection<R>) in tests.CompileTest2.RequestMap<java.lang.Object> cannot be applied to <tests.CompileTest2.DeltaRequest,double[]>(java.util.Collection<tests.CompileTest2.DeltaRequest>)
                DeltaRequest o = m.<DeltaRequest, double[]>test (c);
                                  ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package tests;

import java.util.Collection;
import java.util.Collections;

public class CompileTest2 {

	class Request<R extends Request<R, V>,V> {}
	
	class DeltaRequest extends Request<DeltaRequest, double[]> {}

	class RequestMap<V> {
		public <R extends Request<R, W>, W extends V> R test (Collection<R> c) {
			// In my real code I make use of W of course
			return null;
		}

	}

	public void f () {
		RequestMap<Object> m = new RequestMap<Object> ();
		Collection<DeltaRequest> c = Collections.singleton (new DeltaRequest ());
		// This line not compile?
		DeltaRequest o = m.<DeltaRequest, double[]>test (c);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Remove the type parameter V from RequestMap

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/langtools_data/mustang/6359106/
17-01-2006

EVALUATION The problem has nothing to do with the use of double[]. The problem is bad substitution when multiple type variables are involved.
30-12-2005

EVALUATION javac is wrong, the code should compile.
16-12-2005