Bug 81719

Summary: [compiler][1.5] Correct use of generic abstract classes give compiler error
Product: [Eclipse Project] JDT Reporter: Thomas Barregren <thomas.barregren>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: gatesda, mikea, Olivier_Thomann, zorzella
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Thomas Barregren CLA 2004-12-21 04:46:55 EST
Incorrectly, a class TestImpl<T>, implementing an abstract method
g(T[]) in the superclass AbstractTest<T>, is reported to not
implement AbstractTest<T>.g(Object[]). Notice that the compiler are
looking for the wrong signature. The error message goes away if
Project > Clean... is choosen on the menubar. But as soon as the file
is saved again, the error message comes back. Below I include example
code to replicate this bug. The files compile without warningfs or
errors with Sun's JDK. (Occasionally, I have also noticed that editing
another file also bring back the error message, but I have not figured
out how to replicate this fault.)

I have also filed another bug probably related to this one.


--- AbstractTest.java ------------------------------------------------

public abstract class AbstractTest<T>
{
    public void doTest(T[] a) {
        g(a);
    }
    
    protected abstract void g(T[] a);
}

--- TestImpl.java -----------------------------------------------------

import java.util.Arrays;

// As soon as I save this file, Eclipse complains that "The type TestImpl<T>
// must implement the inherited abstract method AbstractTest<T>.g(Object[])".
// I can remove this error by choosing Project > Clean... from the menubar,
// but it comes back as soons as I save this file again.
public class TestImpl<T> extends AbstractTest<T>
{
    protected void g(T[] a) {
        System.out.println(Arrays.toString(a));
    }
}

--- Main.java --------------------------------------------------------

public class Main
{    
    public static void main(String[] args) {
        AbstractTest<Integer> test=new TestImpl<Integer>();
        Integer[] integers=new Integer[10];
        for(int i=0; i<10; ++i)
            integers[i]=i;
        test.doTest(integers);
    }
}
Comment 1 Thomas Barregren CLA 2004-12-21 05:09:01 EST
See also bug 81721.
Comment 2 Kent Johnson CLA 2005-01-11 14:19:51 EST
This is a problem with how we write out array types of Type Variables.

This case works fine if the 2 types are in the same source file:

public abstract class AbstractTest<T> {
  abstract void array(T[] a);
  abstract void type(T a);
}

class Test<T> extends AbstractTest<T> {
  void array(T[] a) {}
  void type(T a) {}
}

But put Test in its own file & save it (picking AbstractTest up as a binary 
type), and it reports that the method array(T[]) does not override 
AbstractTest.array(Object[]).

The binaryType for AbstractTest is seeing array(Object[]) and not array(T[]).

The method's generic signature should be '([TT;)V' but its not set, so we pick 
it up as '([Ljava/lang/Object;)V'
Comment 3 Philipe Mulet CLA 2005-01-11 18:23:37 EST
Indeed, we did not record the method as requiring a generic signature, due to
array type. Same issue for field&method return types.

Added GenericTypeTest#test455
Comment 4 Philipe Mulet CLA 2005-01-12 04:30:45 EST
*** Bug 82497 has been marked as a duplicate of this bug. ***
Comment 5 Philipe Mulet CLA 2005-01-13 19:29:27 EST
*** Bug 82002 has been marked as a duplicate of this bug. ***
Comment 6 Philipe Mulet CLA 2005-01-14 09:21:56 EST
*** Bug 79145 has been marked as a duplicate of this bug. ***
Comment 7 Jerome Lanneluc CLA 2005-02-15 05:51:57 EST
Verified in I20040214