JDK-6718364 : inference fails when a generic method is invoked with raw arguments
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u23,7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_10
  • CPU: generic,sparc
  • Submitted: 2008-06-24
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
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.
JDK 6 JDK 7
6u24-revFixed 7 b34Fixed
Related Reports
Duplicate :  
Description
The following program does not compile:

class X<T> {}
class Test {
        public void test() {
                m(new X<X<Integer>>(), new X()); // compile error in javac
        }
        public <T> void m(X<T> x, T t) {}
}

ACTUAL BEHAVIOR: does not compile

EXPECTED BEHAVIOUR: compile with warning

Comments
SUGGESTED FIX A webrev for this fix is available at http://sa.sfbay.sun.com/projects/langtools_data/7/6718364/
08-08-2008

WORK AROUND A good workaround is to explicitely specify method type parameters as in: class X<T> {} class Test { public void test() { this.<X<Integer>>m(new X<X<Integer>>(), new X()); // compile error in javac } public <T> void m(X<T> x, T t) {} } as this disable type-inference.
24-06-2008

EVALUATION This is a bug in the implementation of the unchecked subtyping algorithm in Types.isSubtypeUnchecked(). Currently javac does not consider UndetVar types for unchecked subtyping. The result is that, in this case, javac fails to realize that a raw actual is compatible (with warning) to an instantiated undet var. Type variable T is inferred (JLS 15.12.2.7) to be X<Integer> after deriving an equality constraint from the first actual argument. The method is applicable if both: *) X<X<Integer>> <: X<X<Integer>> --> trivially true *) X <: X<Integer> --> there exist an unchecked conversion from X to X<Integer> For the above reasons the method call should be accepted with warning by javac. The reason for which javac rejects the code lies in a subtyping test that is triggered during type-inference: X <: U, where U is an undetvar type, whose instantiation field has already been set to the type X<Integer> Since the current javac implementation of unchecked conversion is buggy, javac fails to consider X as an unchecke subtype of the (already insantiated) undetvar U.
24-06-2008