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

Elements.overrides does not check the return type of the methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • 19, 20, 21
    • core-libs
    • In Review
    • generic
    • generic

      The current implementation of javax.lang.model.Elements.overrides does not take into account the return type of the method.

      JavacElements.java
        @DefinedBy(Api.LANGUAGE_MODEL)
          public boolean overrides(ExecutableElement riderEl,
                                   ExecutableElement rideeEl, TypeElement typeEl) {
              MethodSymbol rider = cast(MethodSymbol.class, riderEl);
              MethodSymbol ridee = cast(MethodSymbol.class, rideeEl);
              ClassSymbol origin = cast(ClassSymbol.class, typeEl);

              return rider.name == ridee.name &&

                     // not reflexive as per JLS
                     rider != ridee &&

                     // we don't care if ridee is static, though that wouldn't
                     // compile
                     !rider.isStatic() &&

                     // Symbol.overrides assumes the following
                     ridee.isMemberOf(origin, types) &&

                     // check access and signatures; don't check return types
                     rider.overrides(ridee, origin, types, false);
          }

      This seems to be working as designed by the last comment if that is the case then is it possible to implement another convenience method which does take into account the return type as in Symbol.java.

            nbenalla Nizar Benalla
            ksrini Kumar Srinivasan
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: