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

Reference method ambiguous on overrided protected method w. generic params

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      java version "1.5.0_16"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
      Java HotSpot(TM) Client VM (build 1.5.0_16-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Versione 5.1.2600]
      (Italian)

      A DESCRIPTION OF THE PROBLEM :
      I found a wrong compile error "reference to method is ambiguous" when calling a method with a row parameter that overrides a protected method with a generic parameter, and there is another method equally accessible and applicable, but less specific.
      If the overridden method is declared public instead of protected, no problem arises. The abstract modifier has no relevance.
      This particular situation can happen when trying to generify a class, leaving unchanged all existing subclasses.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the supplied source code (each class in its own compilation unit).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All should compile fine.
      Specifically, call to methodAB(BVO) in CMgr.methodC() should be resolved as CMgr.methodAB(BVO), as this is the most specific method accessible and applicable.
      ACTUAL -
      Compiler error in CMgr.methodC():
      - reference to methodAB is ambiguous, both method methodAB(AVO<?>) in ABMgr and method methodAB(BVO) in CMgr match

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class AVO<Type> {
      }

      public class BVO<Type> extends AVO<Type> {
      }

      public abstract class ABMgr {
          public abstract void methodAB(AVO<?> vo);
          protected abstract void methodAB(BVO<?> vo);
      }

      public abstract class CMgr extends ABMgr {
          @Override
          public void methodAB(BVO vo) {
          }
          public void methodC() {
              methodAB(new BVO()); //compiler error
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Make ABMgr.methodAB(BVO<?>) public.
      But that's not always possible, e.g. if some existing code override it with protected accessibility.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ryeung Roger Yeung (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: