# Thursday, 01 May 2014
« Arraycopy HotSpot Vulnerability Fixed in... | Main | Default and Static Interface Methods »
Java Method Overriding Is FUBAR Part 9 of ∞

Java 8 introduces default methods. In the current HotSpot implementation this makes adding a private method to a non-final class a binary breaking change (contrary to what the JLS says about this).

Here's an example. Suppose you have two separate code bases Lib and App, shipped by different parties. App depends on Lib.

Lib defines a class B:

public class B {
}

App defines an interface I and a class D:

public interface I {
  default void m() {
    System.out.println("I.m");
  }
}

public class D extends B implements I {
  public static void main(String[] args) {
    D d = new D();
    d.m();
  }
}

All is well in the world. Now Lib ships a new version that includes a new version of class B:

public class B {
  private void m() { }
}

Now when you run D the output is:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method B.m()V from class D
        at D.main(D.java:4)

You could argue that this is "just" an implementation bug, but I posted it as part of this series because it is symptomatic of the mess that is Java's method dispatch story.

Thursday, 01 May 2014 09:38:36 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
Thursday, 05 June 2014 21:37:48 (W. Europe Daylight Time, UTC+02:00)
This sounds like the problem i reported about half a year ago. Hear is some part of my report http://openjdk.5641.n7.nabble.com/Access-Checking-for-MethodHandles-Lookup-broken-td168297.html . Unfortunatly this is not the full thread.

I made a quick check a few days ago with an actual offical jdk 8 Release and it seems that NY problems wäre fixed. Haven't time to look till now how it is fixed. But maybe they missed some corner cases.
Sebastian Sickelmann
Name
E-mail
Home page

I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.

Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)

Answer:  
Comment (HTML not allowed)  

Live Comment Preview