Bug 146383 - Compiler too lax on matching generic method signatures
Summary: Compiler too lax on matching generic method signatures
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-10 11:13 EDT by Scott M Stark CLA
Modified: 2006-06-27 10:13 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Scott M Stark CLA 2006-06-10 11:13:36 EDT
The following class compiles and runs under eclipse(Version: 3.1.2 Build id: M20060118-1600), but will not even compile under the sun jdk(1.5.0_05-b05).

import java.util.ArrayList;
import java.util.Arrays;

class X
{  
}
class Z
{
   
}
class Y<T>
{
   public T t;
   public Y(T t)
   {
      this.t = t;
   }
   public String toString()
   {
      StringBuffer tmp = new StringBuffer("Y(");
      tmp.append(System.identityHashCode(this));
      tmp.append("),t=");
      tmp.append(System.identityHashCode(t));
      return tmp.toString();
   }
}
public class TestAddAll
{
   private static ArrayList<Y<X>> y = new ArrayList<Y<X>>();
   public static void setY(Y[] array)
   {
      y.addAll(Arrays.asList(array));
      System.out.println("setY: "+y);
      Y<X> ay = y.get(0);
      System.out.println("Y.t instanceof X: "+(ay.t instanceof X));
   }
   public static void main(String[] args)
   {
      ArrayList<Y<Z>> yz = new ArrayList<Y<Z>>();
      yz.add(new Y<Z>(new Z()));
      Y[] array = {};
      array = yz.toArray(array);
      setY(array);
   }
}


The result when run under eclipse is:
setY: [Y(25358555),t=26399554]
Y.t instanceof X: false

The result when trying to compile under the sun jdk is:
[starksm@banshee9100 tests]$ javac TestAddAll.java
TestAddAll.java:28: cannot find symbol
symbol  : method addAll(java.util.List<Y>)
location: class java.util.ArrayList<Y<X>>
      y.addAll(Arrays.asList(array));
       ^
1 error

This error seems correct as I should not be able to add an array of Y<Z> to a List<Y<X>> as I am able to do under eclipse.
Comment 1 Kent Johnson CLA 2006-06-14 11:56:00 EDT
This is fixed in 3.2RC7.
Comment 2 Philipe Mulet CLA 2006-06-27 06:08:33 EDT
closing. maxime pls add a regression test
Comment 3 Maxime Daniel CLA 2006-06-27 10:13:11 EDT
Released MethodVerifyTest#94 in HEAD.