[Java] Stepping on a JDK compiler bug

Probably the one who stepped on

[JDK-8143647] Javac compiles method reference that allows results in an IllegalAccessError

~~ * As will be described later, this is an event that occurred in ** Oracle JDK ** instead of OpenJDK, so it is honestly subtle whether it is the same bug. .. .. ~~

Postscript

The Oracle JDK Bug Database had the same issue. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8143647

What happened

Classes compiled with ** Oracle JDK 8u92 ** on Solaris somehow crash at runtime with ʻIllegalAccessError`.

A class compiled with Eclipse Mars 2 (4.5.2) on Windows 7 (x64) with the same source works fine. .. ..

If you look into the bytecode with javap -c, the place where ** method reference ** is used is not the concrete class in the source code, but its parent class, the invisible (package private) abstraction. It was replaced by a class.

The procedure for reproducing the above issue is as follows.

1) Create default-scoped abstract class with concrete method
2) Create a concrete public class extending the above class in the same package
3) Use a method reference to this inherited method in a class outside of the package 

On the other hand, the source that simplifies the problematic class and the class to which the method is referenced is

simplification


package inner;
abstract class AbstractHoge {
    public String getSomething() {
        ...
    }
}

package inner;
public class Hoge extends AbstractHoge {
}

package outer;
import inner.Hoge;
...
public class Fuga {
    public void doSomething(List<Hoge> list) {
        Map<String, List<Hoge>> map = 
            list.stream().collect(Collectors.groupingBy(Hoge::getSomething));
        ...
    }
}

With such a feeling, the activation conditions have been satisfied brilliantly. .. ..

solution

In the above issue, it seems that it has been backported around 8u102 or 8u111, so update to a newer version of Oracle JDK. ⇒ Actually, the problem was solved in the class compiled with ** Oracle JDK 8u161 **.

Recommended Posts

[Java] Stepping on a JDK compiler bug
Install Java Open JDK 8 on CentOS 7
Build a Java development environment on Mac
java core: HotSpot compiler crashes on SIGSEGV
JDK 8 is a heavy problem on MacOS
Deploy a Java web app on Heroku
Java installation jdk
A story about the JDK in the Java 11 era
Create a Lambda Container Image based on Java 15
Build a Java runtime environment on Sakura VPS
I tried running Java on a Mac terminal
Create a Java development environment using jenv on Mac
I tried using Log4j2 on a Java EE server
[Java] How to execute tasks on a regular basis
Java SE Development Kit (JDK) setup procedure on Windows
Creating a lightweight Java environment that runs on Docker
Let's touch on Java
Q & A about JDK
Install Java on Mac
[Java] Create a filter
Run PostgreSQL on Java
java build a triangle
Brainfuck-> Java bytecode compiler
Run R from a tomcat-powered Java process on Amazon Linux
How to deploy a kotlin (java) app on AWS fargate
Java Language Feature and How it Produced a Subtle Bug
Try Hello World using plain Java on a Docker container