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

Incorrect attribution of method invocations of Object methods on interfaces

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 18
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API, Class file construct
    • Scope:
      JDK

      Description

      Summary

      javac is producing suspicious results for code like (note toString is a mirror of a java.lang.Object method, the suspicious results only happen for methods that are mirror methods from java.lang.Object):

      interface I {
          public String toString();
          public String test();
      }
      interface J extends I {}

      The suspicious results are twofold:

      • Trees.isAccessible(..., I.toString, J) (i.e. accessibility check for I.toString as a member of J, in some scope/context) returns false. But I.toString is an inherited member of J and should be accessible under normal circumstances.
      • invocations like J j = null; j.toString(); will be attributed as referring to java.lang.Object.toString, rather than to I.toString (J.toString in classfile). This is observable either through the Trees.getElement API, or in the classfile

      In both cases, this is different from behavior where one would use test instead of toString.

      Problem

      As seen in the Summary section, javac is producing some suspicious results. A significant contributing factor is that javac's internal model uses java.lang.Object as the supertype of interface types.

      Solution

      The proposal is for javac's behavior w.r.t. methods mirroring java.lang.Object methods and superinterface methods to be consistent.

      Specification

      The proposal is that, in the above example:

      • Trees.isAccessible(..., I.toString, J) will return true
      • invocations of java.lang.Object methods on interfaces in the classfile will use invokeinterface referring to the interface, which is consistent with JLS 9.2. This will be done regardless of whether the interface declares the method explicitly or not.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              jlahoda Jan Lahoda
              Reviewed By:
              Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: