Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6356673
Votes 1
Synopsis javac incorrectly generates "reference to <xx> is ambiguous"
Category java:compiler
Reported Against
Release Fixed 7(b05), 6u10(b13) (Bug ID:2145975)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 6365166 , 6499258 , 6507334
Submit Date 29-NOV-2005
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
 customer  Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The overload resolution mechansm for javac 1.5 seems not to cope with the pattern used in the attached code

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the test application

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
should compile and resolve the overload
ACTUAL -
javac failed, with error deatiled below

ERROR MESSAGES/STACK TRACES THAT OCCUR :
reference to addAll is ambiguous, both method addAll(java.util.Collection<? extends E>) in java.util.Collection<? super A> and method addAll(java.util.Collection<? extends E>) in java.util.List<? super A> match
        l.addAll(getRelated(b));

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Collections;
import java.util.List;


public class Test<A,B> {

    private List<A> getRelated(B b) {
        return Collections.emptyList();
    }
    
    public <L extends List<? super A>> L addOrCreate(B b,L l) {
        l.addAll(getRelated(b));
        return l;
    }
    
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
dont use this pattern, chnage to interfaces, and developed code.
Posted Date : 2005-11-29 22:26:47.0

Simplified testcase submitted by another customer:

import java.util.Set;

public class GenericCaptureAddingTest {

    public void test(Set<? super Number> numbers, Set<Number> someNumbers) {
        numbers.addAll(someNumbers);
    }

}
Posted Date : 2006-09-18 22:02:40.0
Work Around
N/A
Evaluation
This must have been fixed by one of my fixes in Mustang b65 or b67.
Posted Date : 2005-12-30 20:29:03.0

Yep.  This was fixed as part of 6268476.
Posted Date : 2006-01-26 19:08:02.0

This is failing again.
Posted Date : 2006-10-17 16:04:28.0

The problem was that containsType does not produce the correct answer for
a wildcard and its capture, or two wildcards of the same captured type.
Posted Date : 2006-11-27 06:26:54.0
Comments
  
  Include a link with my name & email   

Submitted On 31-DEC-2005
skells
This may have been fixed in 1.6 but hat is not released. This should be evaluated against 1.5, the current version.
This is stil a bug in 1..5_06, and needs fixing there


Submitted On 31-DEC-2005
skells
This may have been fixed in 1.6 but hat is not released. This should be evaluated against 1.5, the current version.
This is stil a bug in 1..5_06, and needs fixing there


Submitted On 31-DEC-2005
skells
This may have been fixed in 1.6 but hat is not released. This should be evaluated against 1.5, the current version.
This is stil a bug in 1..5_06, and needs fixing there


Submitted On 01-JAN-2006
skells
sorry for the multiple comments above - browser hung


Submitted On 25-NOV-2006
corky
I was just bitten by the bug in Mustang build 104 (Linux).  The same code compiles without incident in Java 1.5.0_08-b03.


Submitted On 26-MAR-2007
-bsx-
This bug is still present in 1.6.0-b105 (official release version) as reported by #6507334.
Please reopen!


Submitted On 12-APR-2007
This bug is still present, please sort this out - it's been fixed once already, 
surely it's a regression issue?  Easy Peasy to fix.

I used the latest version: 
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_01-b06, mixed mode)


Submitted On 29-JUN-2007
this is still an issue. please advise.


Submitted On 26-FEB-2008
p_a_harvey
I submitted a fresh report for this problem before seeing this one. The problem seems to have been fixed in 1.5 and 1.7. According to an email I received from Sun, a fix is in the works for 1.6.


Submitted On 20-OCT-2008
violante
this is still an issue on JDK 1.6.0.7 (Win32).


Submitted On 07-SEP-2009
pedroerg
Pedroerg:

A have the same problem in jdk1.6.0.06 (netbeans 6.7.1, win32 vista)



PLEASE NOTE: JDK6 is formerly known as Project Mustang