JDK-6388596 : generics: erasure name clash
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2006-02-22
  • Updated: 2010-04-02
  • Resolved: 2009-03-13
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59g)
Java HotSpot(TM) Client VM (build 1.6.0-beta-b59g, mixed mode, sharing)

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pxi32dev-20051104)
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20051103 (JIT enabled)
J9VM - 20051027_03723_lHdSMR
JIT  - 20051027_1437_r8
GC   - 20051020_AA)
JCL  - 20051102


ADDITIONAL OS VERSION INFORMATION :
Debian GNU/Linux Sarge 2.6.8 i686

A DESCRIPTION OF THE PROBLEM :
In the described case 'javac' either reports an erasure name clash error or compiles silently according to whether all classes are compiled at once or one after the other.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
(1) Create 'Fooable.java', 'Foo.java' and 'Bar.java' as given in a common working directory.
(2) Delete all class files in the working directory.
(3) Execute 'javac Bar.java'.
(4) Delete all class files in the working directory.
(5) Execute 'javac Foo.java' followed by 'javac Bar.java'.
(6) Execute 'java Bar'.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Steps (3) and (5) are expected to give the same result, i.e. a working 'Bar.class'.


ACTUAL -
Step (3) results in an erasure name clash error report.
Step (5) processes fine and (6) prints 'false' as expected.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Bar.java:1: name clash: equals(T) in Fooable<Bar> and equals(java.lang.Object) in java.lang.Object have the same erasure, yet neither overrides the other
public class Bar extends Foo<Bar> {
       ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
//Fooable.java
public interface Fooable<T> {
    public boolean equals(T t);
}

//Foo.java
public class Foo<T extends Foo<T>> implements Fooable<T> {
    public boolean equals(T t) {
        return false;
    }
}

//Bar.java
public class Bar extends Foo<Bar> {
    public static void main(String[] args) {
        Bar a = new Bar();
        Bar b = new Bar();

        System.out.println(a.equals(b));
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Compile stepwise.

Comments
EVALUATION Not reproducible since jdk 7 b27 (see 5009937)
13-03-2009

EVALUATION This is a problem with bridge methods. The class Foo should not compile as it needs a bridge method to Fooable.equals.
16-10-2006

EVALUATION This appears to be a problem with substitution.
22-02-2006