Skip to content

Commit a2ee859

Browse files
xerialgzm0
authored andcommitted
Fix scala-js#3921: Work around JDK-6265952: MethodAccessorImpl NoClassDefError
1 parent 4cbf1f9 commit a2ee859

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

sbt-plugin/src/main/scala/org/scalajs/sbtplugin/LinkerImpl.scala

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,36 @@ object LinkerImpl {
7777
"scala.",
7878
"org.scalajs.linker.interface.",
7979
"org.scalajs.logging.",
80-
"org.scalajs.ir."
80+
"org.scalajs.ir.",
81+
/*
82+
* A workaround for the OpenJDK bug 6265952 (#3921)
83+
* https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6265952
84+
*
85+
* It manifests as a `java.lang.NoClassDefFoundError` being thrown,
86+
* claiming the class `MethodAccessorImpl` is missing. The package of the
87+
* class is implementation specific. The currently known packages are
88+
* listed as prefixes below.
89+
*
90+
* The bug is triggered when calling `java.lang.Method#invoke` if both of
91+
* the following conditions are met:
92+
*
93+
* - this is the 15th (or later) time `invoke` is called on this instance,
94+
* - the `ClassLoader` of the method's owning class does not make
95+
* `MethodAccessorImpl` available.
96+
*
97+
* Depending on the JDK implementation, the system property
98+
* `sun.reflect.inflationThreshold` controls the invocation count
99+
* threshold and can serve as a temporary workaround (e.g. set
100+
* `-Dsun.reflect.inflationThreshold=30`)
101+
*
102+
* To work around the issue, this `ClassLoader` delegates loading of
103+
* classes in these internal packages to the parent `ClassLoader`.
104+
* Additional package prefixes may need to be added in the future if the
105+
* internal package names change or another implementation uses a
106+
* different name.
107+
*/
108+
"sun.reflect.",
109+
"jdk.internal.reflect."
81110
)
82111

83112
override def loadClass(name: String, resolve: Boolean): Class[_] = {

0 commit comments

Comments
 (0)