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

13.4.12: Adding methods can break binary compatibility

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • specification

      As pointed out at [1], JLS8 13.4.12 contains a false claim:

      "Adding a method or constructor declaration to a class will not break compatibility with any pre-existing binaries, even in the case where a type could no longer be recompiled because an invocation previously referenced a method or constructor of a superclass with an incompatible type. The previously compiled class with such a reference will continue to reference the method or constructor declared in a superclass."

      It's false because adding a private method in a superclass can cause a resolution failure when invoking a public method inherited by a subclass. (JLS 15.12.4.3 and JVMS 5.4.3.* are in sync on this.)

      The problem arises if the public method was originally declared as a default method in a superinterface. Then, the private method interposes between the superinterface and the subclass (the qualifying type of the invocation).

      [1] http://weblog.ikvm.net/PermaLink.aspx?guid=cc9b6d6f-8f24-43b2-a6ef-18ba0758c35d

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: