JDK-7011874 : Overriding generic method fails
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u23
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2011-01-12
  • Updated: 2012-09-06
  • Resolved: 2011-01-13
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

A DESCRIPTION OF THE PROBLEM :
In the the attached example class Impl attempts to implement generic method work() declared in interface Algo.
javac fails to compile it.

I believe that the code is correct.
Furthermore, if fake type parameter is added to work(), javac compiles the code just fine.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the example.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation should succeed.
ACTUAL -
Compilation fails.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Impl.java:1: Impl is not abstract and does not override abstract method <V>work(V,X) in Algo
public class Impl<X> implements Algo<X> {
       ^
Impl.java:2: method does not override or implement a method from a supertype
    @Override
    ^
2 errors

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public interface Val<V extends Val<V, X>, X> {
    V add(V v);

    X x();
}

public interface Algo<X> {
    <V extends Val<V, X>>
    V work(V v, X x);
}

public class Impl<X> implements Algo<X> {
    @Override
    public <V extends Val<V, X>>
    V work(V v, X x) {
        return v;
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Add fake type parameter W to work():

public interface Algo<X> {
    <V extends Val<V, X>, W>
    V work(V v, X x);
}

public class Impl<X> implements Algo<X> {
    @Override
    public <V extends Val<V, X>, W>
    V work(V v, X x) {
        return v;
    }
}

Comments
EVALUATION Not repriducible in JDK 7 since fix of 6729401.
13-01-2011