Want to show your appreciation?
Please a cup of tea.

Friday, June 23, 2006

Eclipse compiler bug: false ambiguous method error

This is an eclipse bug in the area of supporting JDK 1.5 Generics. The bug was discovered in 3.1.2. Not sure about 3.2 but I couldn't find similar bug report in bugzilla.

To reproduce the bug, use one of the class below. Both of them are compiled fine with javac 1.5.0_06.

Link to bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=148504

List 1 - A theoretical example.

public class EclipseAmbiguousBug {
   interface IWorker<E> {
     void add(E e);
   }

   interface IPerson<E> {
     void add(E e);
   }

   interface IFather<E> extends IWorker<E>, IPerson<E>{   }

   interface IMother<E> extends IPerson<E> {
     void add(E e);
   }

   interface IChild<E> extends IFather<E>, IMother<E> {   }
   static class Child<E> implements IChild<E> {
     public void add(E e) {}
   }

   public static void main(String[] args) {
     IChild c = new Child();
     c.add(""); // correct warning
     IChild<String> cg = new Child<String>();
     cg.add(""); // false ambiguous error
   }
}

List 2 - A practical example.

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

public class EclipseAmbiguousBug2 {
   interface Addable<E> {
     boolean add(E e);
   }
   interface XCollection<E> extends Collection<E>, Addable<E> {}
   interface XSet<E> extends XCollection<E>, Set<E> {}

   static class TestXSet<E> extends AbstractSet<E> implements XSet<E> {
     public boolean add(E e) {return false;}
     public Iterator<E> iterator() {return null;}
     public int size() {return 0;}
   }

   public static void main(String[] args) {
     XSet xs = new TestXSet();
     xs.add(""); // correctly generated warning
     XSet<String> xs2 = new TestXSet<String>();
     xs2.add(""); // false ambiguous error message
   }
}

No comments:

Post a Comment