[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. .. .. ~~
The Oracle JDK Bug Database had the same issue. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8143647
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. .. ..
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 **.
public
.Recommended Posts