javac bug: dispatch to multiply inherited defenders

Brian Goetz brian.goetz at oracle.com
Wed Oct 27 20:04:11 PDT 2010


This test case fails to compile:

public class MultipleInheritanceTest extends DefenderTestCase {
     private interface A {
         public extension int get() default Implementations.one;
     }

     private interface B {
         public extension int get() default Implementations.one;
     }

     private static class X implements A, B { }

     public void testValidMI() {
         assertDefender(X.class, "get", new Class[] { }, 
Implementations.class, "one");
         X x = new X();
         assertEquals(1, x.get());        // @@@
         assertEquals(1, ((A) x).get());
         assertEquals(1, ((B) x).get());
     }
}

We get the error at the line marked // @@@

test-compile:
     [javac] Compiling 3 source files to 
/home/brian/work/mangler/trunk/defender/build/test-classes
     [javac] 
/home/brian/work/mangler/trunk/defender/test/src/junit/MultipleInheritanceTest.java:20: 
reference to get is ambiguous, both method get() in B and method get() in A match
     [javac]         assertEquals(1, x.get());
     [javac]                          ^


The static type of 'x' is 'X', which is a class that has a get() method.  That 
method happens to be inherited from both A and B, but their signatures and 
defaults are the same so they should be compatible methods.

The testValidMI() method should generate an invokevirtual and two 
invokeinterface invocations.



More information about the lambda-dev mailing list