IllegalAccessError when using a public method reference of a package-private class through a public subclass from another package
Yesterday I faced an interesting issue after deploying my Java 8 webapp on Tomcat 8. Rather than how to solve this issue I'm more interested in understanding why that happens. But let's start from the beginning. I have two classes defined as follows: Foo.java package package1; abstract class Foo { public String getFoo() { return "foo"; } } Bar.java package package1; public class Bar extends Foo { public String getBar() { return "bar"; } } As you can see, they are in the same package and, ultimately, end up in the same jar, let's call it commons.jar . This jar is a dependency of my webapp (i.e.