Skip to content

Dotty generates code that cause Exception in thread "main" java.lang.IllegalAccessError during runtime. #13897

Closed
@megri

Description

@megri

Compiler version

All versions of Dotty seem to be affected.
Java 8 and 11, possibly newer ones as well.

Minimized code

build.sbt

scalaVersion := "3.1.0"
// scalaVersion := "3.0.0"
// scalaVersion := "2.13.6" // 2.13.6 not affected
classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat // recommended by sbt; does not change outcome
libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.1.0"

Program

package bugreport

import com.google.cloud.datastore.Query

object Main {
  def main(args: Array[String]): Unit = {
    val query = Query.newEntityQueryBuilder.setKind("Bug").setLimit(10) // One "setX"-call seems ok.
    println(s"query: $query")
  }
}

Output

Compilation succeeds. Fails at runtime with

sbt:bugreport-illegalaccesserror> run
[info] running bugreport.Main
[error] (run-main-7) java.lang.IllegalAccessError: Error running public static void bugreport.Main.main(java.lang.String[]).
[error] java.lang.IllegalAccessError: failed to access class com.google.cloud.datastore.StructuredQuery$BuilderImpl from class bugreport.Main$ (com.google.cloud.datastore.StructuredQuery$BuilderImpl and bugreport.Main$ are in unnamed module of loader sbt.internal.FlatLoader @65e7072e)
[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.
[error] java.lang.IllegalAccessError: Error running public static void bugreport.Main.main(java.lang.String[]).
[error] java.lang.IllegalAccessError: failed to access class com.google.cloud.datastore.StructuredQuery$BuilderImpl from class bugreport.Main$ (com.google.cloud.datastore.StructuredQuery$BuilderImpl and bugreport.Main$ are in unnamed module of loader sbt.internal.FlatLoader @65e7072e)
[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.
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1
[error] Total time: 1 s, completed 7 Nov 2021, 11:07:28

Expectation

Should work as in 2.13.6

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions