Bug 382469 - Ambiguous method invocation
Summary: Ambiguous method invocation
Status: VERIFIED DUPLICATE of bug 383780
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.8.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-13 05:28 EDT by Samuel Wicky CLA
Modified: 2012-08-14 05:14 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Wicky CLA 2012-06-13 05:28:37 EDT
Build Identifier: I20120531-1500

With the compiler of eclipse 3.7 the following example compiled and the call of the method bar in the following example invoked the second method ( void bar(int intValue, Object... objs) ).

The compiler of eclipse 4.2 (RC3) tells me now that the method bar is abiguous.

-----------------------------------------------
public class Main {

	public static void main(String[] args) {
		bar(5); // Compiler error: The method bar(Object[]) is ambiguous for the type Main
	}

	private static void bar(Object... objs) {}

	private static void bar(int intValue, Object... objs) {} // this method was invoked with the compiler of eclipse 3.7

}
-----------------------------------------------

Reproducible: Always

Steps to Reproduce:
1. Copy the example of the description into the IDE
2. Look at the compiler errors
Comment 1 Srikanth Sankaran CLA 2012-06-13 05:34:46 EDT
Javac8 complains:

C:\jtests>C:\jdk-7-fcs-bin-b147-windows-i586-27_jun_2011\jdk7\jdk1.7.0\bin\javac
 -Xlint:unchecked -Xlint:rawtypes -Xlint:varargs -Xlint:deprecation -sourcepath
c:\jtests X.java
X.java:4: error: reference to bar is ambiguous, both method bar(Object...) in X
and method bar(int,Object...) in X match
        bar(5); // Compiler error: The method bar(Object[]) is ambiguous for the
 type Main
        ^
1 error

//--------------

I believe this is the intended behavior and eclipse behavior change was
in response to javac change. I'll dig up the original bug report shortly.
Comment 2 Ayushman Jain CLA 2012-07-25 13:39:16 EDT
Srikanth, do we want to include this case too under the system property being worked on in bug 383780? (The patch there doesn't fix this issue)
Comment 3 Srikanth Sankaran CLA 2012-07-26 04:40:28 EDT
(In reply to comment #2)
> Srikanth, do we want to include this case too under the system property being
> worked on in bug 383780? (The patch there doesn't fix this issue)

After due analysis and confirming that this is the same case - yes, please.
Comment 4 Ayushman Jain CLA 2012-08-01 04:12:34 EDT
Use -DtolerateIllegalAmbiguousVarargsInvocation = true to get this code compiled with 4.3/Juno SR1 once bug 383780 is fixed.

*** This bug has been marked as a duplicate of bug 383780 ***
Comment 5 Srikanth Sankaran CLA 2012-08-06 05:06:35 EDT
Verified that the patch proposed at bug 383780 addresses the 
present problem.
Comment 6 Srikanth Sankaran CLA 2012-08-14 05:14:31 EDT
Verified for 3.8.1 using Build id: M20120809-1000