United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6718364 inference fails when a generic method is invoked with raw arguments
JDK-6718364 : inference fails when a generic method is invoked with raw arguments

Details
Type:
Bug
Submit Date:
2008-06-24
Status:
Closed
Updated Date:
2011-05-17
Project Name:
JDK
Resolved Date:
2011-05-17
Component:
tools
OS:
generic,solaris_10
Sub-Component:
javac
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6u23,7
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Duplicate:

Sub Tasks

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
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.
                                     
2008-06-24
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.
                                     
2008-06-24
SUGGESTED FIX

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



Hardware and Software, Engineered to Work Together