Bug 140168 - Ambiguous Failure in Connection with Varargs
Summary: Ambiguous Failure in Connection with Varargs
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-04 10:44 EDT by Senex CLA
Modified: 2006-05-05 03:40 EDT (History)
4 users (show)

See Also:


Attachments
Patch (1.62 KB, patch)
2006-05-04 11:50 EDT, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Senex CLA 2006-05-04 10:44:14 EDT
Since Eclipse SDK 3.2RC2 there is an ambigous error for the following method signatures:  
  public void setItem(Object id, Object value, String... groups);
  public void setItem(Item item, String... groups);

Where the methode invocation
	c.setItem(new Item("id", "value"), "group-a", "group-b");
becomes ambigous.

This code works properly with Eclipse SDK 3.1.2, jdk1.5.0_01 and jdk1.5.0_04. That means that always the expected methode was called.
Comment 1 Olivier Thomann CLA 2006-05-04 10:50:22 EDT
Test case:
public class X {

    public void setItem(Object id, Object value, String... groups) {}
    public void setItem(Item item, String... groups) {}
    
    public static void main(String[] args) {
    	X x = new X();
    	x.setItem(new Item("id", "value"), "group-a", "group-b");
    }
}
class Item {
	public Item(String s, String s1) {}
}

We report:
----------
1. ERROR in D:\tests_sources\X.java
 (at line 8)
	x.setItem(new Item("id", "value"), "group-a", "group-b");
	  ^^^^^^^
The method setItem(Object, Object, String[]) is ambiguous for the type X
----------
1 problem (1 error)

javac 1.5.0_07 and 6.0b81 compile that code successfully.
Comment 2 Olivier Thomann CLA 2006-05-04 11:23:13 EDT
Disassembled code:
     0  new X [2]
     3  dup
     4  invokespecial X() [3]
     7  astore_1
     8  aload_1
     9  new Item [4]
    12  dup
    13  ldc <String "id"> [5]
    15  ldc <String "value"> [6]
    17  invokespecial Item(java.lang.String, java.lang.String) [7]
    20  iconst_2
    21  anewarray java.lang.String [8]
    24  dup
    25  iconst_0
    26  ldc <String "group-a"> [9]
    28  aastore
    29  dup
    30  iconst_1
    31  ldc <String "group-b"> [10]
    33  aastore
    34  invokevirtual X.setItem(Item, java.lang.String[]) : void [11]
    37  return

So the second one is called.
Comment 3 Kent Johnson CLA 2006-05-04 11:50:46 EDT
Created attachment 40365 [details]
Patch

Straight forward fix for vararg methods with different number of parameters
Comment 4 Kent Johnson CLA 2006-05-04 11:55:27 EDT
Darin, Dani - please approve the attached patch
Comment 5 Dani Megert CLA 2006-05-04 12:05:32 EDT
Approving for 3.2 RC3.
Comment 6 Kent Johnson CLA 2006-05-04 12:10:20 EDT
Jeff - can you give this one a thumbs up?
Comment 7 Darin Wright CLA 2006-05-04 12:11:27 EDT
+1 for RC3
Comment 8 Jeff McAffer CLA 2006-05-04 12:13:48 EDT
+1 
Comment 9 Kent Johnson CLA 2006-05-04 12:14:46 EDT
Added VarargsTest #47
Comment 10 Kent Johnson CLA 2006-05-04 13:29:07 EDT
Released into HEAD
Comment 11 Olivier Thomann CLA 2006-05-04 20:36:47 EDT
Verified for 3.2RC3 using I20060504-1600.
Comment 12 Senex CLA 2006-05-05 03:40:52 EDT
Works well again. Thank you for quick work.

Verified with:
Version: 3.2.0
Build id: I20060504-2000