Skip to content

IllegalAccessError when calling java method defined in base class #8661

Closed
@ohze

Description

@ohze

Minimized code

  • pk/B.java
package pk;
class B {
    public void hi() { System.out.println("hi"); }
}
  • pk/C.java
package pk;
public class C extends B {
    public C() {}
}
  • Main.scala
import pk.C
object Main {
  def main(args: Array[String]): Unit = {
    identity(new C).hi()
  }
}

Output

[info] running (fork) Main 
[error] Exception in thread "main" java.lang.IllegalAccessError: tried to access class pk.B from class Main$
[error]         at Main$.main(Main.scala:5)
[error]         at Main.main(Main.scala)

Expectation

run successfully as in scala 2

Notes

In sbt: set Compile/run/fork := true to mute another errors:

[error] java.lang.IllegalAccessError: tried to access class pk.B from class Main$
[error] If using a layered classloader, this can occur if jvm package private classes
 are accessed across layers. This can be fixed by changing to the Flat or
 ScalaInstance class loader layering strategies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions