Bug 74032 - [1.5] Generics: bad method referenced when a type variable extends two types
Summary: [1.5] Generics: bad method referenced when a type variable extends two types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-15 20:46 EDT by Luc Bourlier CLA
Modified: 2004-11-04 06:35 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2004-09-15 20:46:52 EDT
I200409140800 + jdt.core from HEAD

I got an NoSuchMethodError when running this code :

import java.util.ArrayList;
import java.util.List;
class TestElement extends ArrayList implements Runnable {
  public void run() {
  }
}
blic class Test <E extends List & Runnable> {
  public Test(E element) {
    element.run();
  }
  public static void main(String[] args) {
    new Test<TestElement>(new TestElement());
  }
}

Exception in thread "main" java.lang.NoSuchMethodError: java.util.List.run()V
	at test.Test.<init>(Test.java:13)
	at test.Test.main(Test.java:16)

It looks like the method invocation referenced java.util.List#run() instead of
java.lang.Runnable#run().

If I reverse the order of 'List' and 'Runnable' in the type declaration, this
test case works (but I expect problems if I try to access List methods).
Comment 1 Philipe Mulet CLA 2004-10-21 08:10:19 EDT
Reproduced in latest.
Comment 2 Philipe Mulet CLA 2004-10-21 08:21:35 EDT
Problem comes from change of Runnable#run() receiver type to List#run(), as 
List is the erasure of type variable. Reversing the order of bounds is changing 
erasure to Runnable, and then method invocation is legite.
Comment 3 Philipe Mulet CLA 2004-10-22 10:39:43 EDT
Workaround is to explicitly cast before invoking method from Runnable.
Comment 4 Philipe Mulet CLA 2004-10-26 09:25:05 EDT
Tweak receiver genericCast insertion.

Added regression tests: GenericTypeTest#test320 & test321.
Fixed
Comment 5 David Audel CLA 2004-11-04 06:35:07 EST
Verified for 3.1M3 with build I200411040100