JDK-7030781 : problem with multiple interface inheritance using bounded type parameters
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2011-03-24
  • Updated: 2012-03-20
  • Resolved: 2011-03-25
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
/opt/jdk1.7.0/bin/javac -version
javac 1.7.0-ea

Build b134
Error occurs on 32bit and 64 Linux systems

ADDITIONAL OS VERSION INFORMATION :
Linux nodeXYZ 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
Linux nodeXYY 2.6.32-22-generic #36-Ubuntu SMP Thu Jun 3 19:31:57 UTC 2010 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
In java 6 problems were reported with inheritance of multiple interfaces, e. g.
http://bugs.sun.com/view_bug.do;jsessionid=38b12cbe58b2634d7bb6dabb8a42?bug_id=6709429
http://bugs.sun.com/view_bug.do?bug_id=6908259

This problems were solved in Java 7. However, the problem still exists if bounded type parameters are used. The compilation of a methods using bounded type parameters inheriting from two interfaces fails. For details see source code below.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try to compile the source reported below using java 7 (e.g. b134)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
successful compilation
ACTUAL -
compilation fails

ERROR MESSAGES/STACK TRACES THAT OCCUR :
/opt/jdk1.7.0/bin/javac  someClass.java
someClass.java:19: types B and A are incompatible; both define x(), but with unrelated return types
    public static <M extends A & B> void somePubStatic(M mx)
                   ^
1 error
make: [covar] Error 1 (ignored)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class someClass {

    interface Top {
        Top x();
    }

    interface A extends Top {
        A x();
    }

    interface B extends Top {
        B x();
    }

    // caused a compiler error in Java 6,
    // but was fixed in Java 7
    interface AB extends A, B {
        AB x();
    }

    // causes compiler error in Java 7
    public static <M extends A & B> void somePubStatic(M mx)
    {
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
  Interestingly, the above code compiles successfully in Eclipse.

Comments
EVALUATION This is not a regression - JDK 6 always meant to reject code like the following: interface I1 { I1 m(); } interface I2 { I2 m(); } class Test { <T extends I1 & I2> T f() { return null; } } And, in fact, it did. However there was a glitch in the JDK 6 compiler, that made the compiler to accept a slight variation of the above program in which the interfaces are moved inside the toplevel class 'Test': class Test { interface I1 { I1 m(); } interface I2 { I2 m(); } <T extends I1 & I2> T f() { return null; } } The above code used to compile with JDK 6 - but the compiler was being clearly inconsistent with the previous case. This glitch got fixed in JDK 7 b02 (5061359) - so the compiler now correctly rejects both programs. As to why the program should be rejected, consider this example: class A {} class B {} interface I1 { A m(); } interface I2 { B m(); } public class Test { <T extends I1 & I2> T f(T t) { A a = t.m(); } //should this compile?? } Current overload resolution rules are not prepared to handle cases in which a type has two override-equivalent members with unrelated return types. This is why this program must be rejected.
25-03-2011