JDK-6794295 : javac does not compile correct source code with generics.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2009-01-15
  • Updated: 2010-04-26
  • Resolved: 2009-01-20
Related Reports
Relates :  
Description
J2SE Version (please include all output from java -version flag):
java version "1.6.0_10"


Does this problem occur on J2SE 1.3, 1.4.x or 1.5?  Yes / No (pick one)
Not tested, however 1.6.0_02 and 1.6.0_04 produce the same problem.


Operating System Configuration Information (be specific):
Windows Server 2003 SP 2


Hardware Configuration Information (be specific):
Toshiba Tecra S5


Bug Description:
javac does not compile correct source code with generics.

Input:

    abstract class Test
    {
        interface Fn<T, R> { }

        interface Pair<T1, T2> { }

        abstract <T> java.util.Comparator<T> asComparator(Fn<Pair<? extends T, ? extends T>, Integer> fn);

        <X> void test(Fn<Pair<? extends X, ? extends X>, Integer> fn)
        {
            asComparator(fn);   // <- compile error
        }
        
        // On the other hand:
        
        interface Single<T1> { }

        abstract <T> java.util.Comparator<T> asComparator2(Fn<Single<? extends T>, Integer> fn);

        <X> void test2(Fn<Single<? extends X>, Integer> fn)
        {
            asComparator2(fn);  // compiles fine
        }
    }


Output:
 
Test.java:12: <T>asComparator(Test.Fn<Test.Pair<? extends T,? extends T>,java.lang.Integer>) in Test cannot be applied to (Test.Fn<Test.Pair<? extends X,? extends X>,java.lang.Integer>)
        asComparator(fn);   // <- compile error
        ^
1 error


Workaround:

this.<X> asComparator(fn);

Comments
EVALUATION This is a bug in Infer.isSubclass that has been fixed in 7 (see 6302954) - please refer to that CR to more info.
20-01-2009