Closed
Description
https://bugs.openjdk.java.net/browse/JDK-8159215
the way we currently compile module classes, assigns the static final MODULE$ from the module class constructor <init>
which is called by <clinit>
. This is prohibited by the spec and will be enforced by JDK9.
./scala-2.11.8/bin/scala
Exception in thread "main" java.lang.IllegalAccessError: Update to static final field scala.tools.nsc.MainGenericRunner$.MODULE$ attempted from a different method (scala.tools.nsc.MainGenericRunner$) than the initializer method <clinit>
at scala.tools.nsc.MainGenericRunner$.<init>(MainGenericRunner.scala:102)
at scala.tools.nsc.MainGenericRunner$.<clinit>(MainGenericRunner.scala)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
If they enforce the restriction and we move the initializers to the only allowed place, <clinit>
, following code will always throw NPE.
class Super {
Object.foo
}
object Singleton extends Super {
def foo = 1
// <clinit> -> new Singleton
// <init> MODULE$ = this
}
Reported by Zoltán Majó. We have discussed the issue. The JDK product team seems have decided that this change is to stay. What it means, is that code compiled both by dotty and Scala cannot use bytecode version 53, unless we drop the final
flag on all MODULE$
.
PING @adriaanm, @lrytz, @retronym. I'll keep you informed on progress.
Metadata
Metadata
Assignees
Labels
No labels