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

Elements.getAllMembers returns methods that are neither inherited nor declared

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • 23
    • 21
    • core-libs
    • None

    Description

      Consider this source:

      public class A {
          public void m() { }
      }

      public interface B {
          void m();
      }

      public class C extends A implements B { }
      ---

      The list returned by Elements.getAllMembers(C) contains B.m. At the same time, Elements.overrides(A.m, B.m, C) returns true.

      Here's a problem with that. According to Elements.getAllMembers specification, that method "Returns all members of a type element, whether inherited or declared directly." Now, B.m is not declared in C. So, it must be inherited. But it cannot be inherited, because JLS 8.4.8.1 says that for a method to be overridden by a class it must not be inherited by that same class.

      Regardless of the direction of causal relationship, if any, between the state of being inherited and the state of being overridden, those states seem to be mutually exclusive. Here's a relevant excerpt from 8.4.8.1. Overriding (by Instance Methods):
      ...
      An instance method mC declared in or inherited by class C, overrides from C another method mI declared in interface I, iff all of the following are true:
       ...
       * C does not inherit mI.
       ...

      ---

      Separately. The word "members" in that method's name evokes JLS. If the method is NOT modelled after JLS, then it should explicitly say so. Otherwise, it should link to JLS sections 8.2. Class Members and 9.2. Interface Members. In this case, the method should also note that _unlike those of JLS_, members returned from the method include constructors. I know that the method explicitly includes constructors now, but it should also draw attention to the fact that it is not how JLS defines members.

      Here's what JLS 8.2 says:

      _Constructors_, static initializers, and instance initializers are not members and therefore are not inherited.

      Here's what the Elements.getAllMembers method says:

      For a class the result also includes its constructors, but not local or anonymous classes.

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              prappo Pavel Rappo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: