Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6356673

javac incorrectly generates "reference to <xx> is ambiguous"

    Details

    • Subcomponent:
    • Resolved In Build:
      b05
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Backports

        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 :
        Microsoft 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.
        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);
            }

        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ahe Peter Ahe
                  Reporter:
                  rmandalasunw Ranjith Mandala (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: