bug
bug copied to clipboard
REPL IllegalAccessError to Java package-protected static member
$ scala
Welcome to Scala 2.12.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_151).
Type in expressions for evaluation. Or try :help.
scala> new p.S().s
res0: String = ""
scala> :pa -raw
// Entering paste mode (ctrl-D to finish)
package p {
class X { def x = J.j }
}
// Exiting paste mode, now interpreting.
scala> val x = new p.X
x: p.X = p.X@25a7fedf
scala> x.x
java.lang.IllegalAccessError: tried to access method p.J.j()Ljava/lang/String; from class p.X
at p.X.x(<pastie>:2)
... 28 elided
scala> :quit
$ cat p/J.java
package p;
public class J {
static String j() { return ""; }
}
$ cat p/S.scala
package p
class S {
def s = J.j
}
IIUC still an issue
scala> new p.X().x
java.lang.IllegalAccessError: class p.X tried to access method 'java.lang.String p.J.j()' (p.X is in unnamed module of loader scala.tools.nsc.interpreter.IMain$TranslatingClassLoader @29c2c826; p.J is in unnamed module of loader scala.reflect.internal.util.ScalaClassLoader$URLClassLoader @253b380a)
at p.X.x(<pastie>:2)
... 32 elided
JVMS 5.4.4 says it must be
declared by a class in the same run-time package
but the pasted class has a different class loader. Splitting the package will never work.