Skip to content

Type inference after erasure uses package private type over public one leading to java.lang.IllegalAccessError at runtime #16474

Closed
@chungonn

Description

@chungonn

Below is a minimal code fragment to reproduce the problem. It works from Scala 3.0 to Scala 3.2.0 and it breaks with Scala 3.2.1 and Scala.3.2.2-RC1

With Scala 3.2.1, when the method jweEncrypt is invoked, it throws a java.lang.IllegalAccessError. With all versions prior to Scala 3.2.1, the method is able to be executed.

Java Version

Java 17

Compiler version

Scala 3.2.1, Scala 3.2.2-RC1

Minimized code

Change the scala3Version to 3.2.0 then run the test suite to see the expected output.

build.sbt

val scala3Version = "3.2.1"

lazy val root = project
  .in(file("."))
  .settings(
    name := "Test",
    version := "0.1.0-SNAPSHOT",

    scalaVersion := scala3Version,

    libraryDependencies ++= Seq(
      "com.nimbusds" % "nimbus-jose-jwt" % "9.25.6",
      "org.scalameta" %% "munit" % "0.7.29" % Test
    )
  )

MySuite.scala

class MySuite extends munit.FunSuite {

  def jweEncrypter(publicJwk: JWK): Try[JWEEncrypter] = Try {
    publicJwk match
      case rsa: RSAKey => new RSAEncrypter(rsa)
      case ec: ECKey => new ECDHEncrypter(ec)
      case _ => throw new RuntimeException(s"Unsupported jwk ${publicJwk}")
  }

  test("JWS signing and verify using private cert pem file") {
    val jwkTry = jweEncrypter(null)
    println(s"jwkTry = ${jwkTry}")
  }
}

Output

Testing started at 3:22 pm ...

Process finished with exit code 255

java.lang.IllegalAccessError: failed to access class com.nimbusds.jose.crypto.impl.BaseJWEProvider from class MySuite (com.nimbusds.jose.crypto.impl.BaseJWEProvider and MySuite are in unnamed module of loader 'app')

	at MySuite.jweEncrypter(MySuite.scala:14)
	at MySuite.$init$$$anonfun$1(MySuite.scala:17)

Expectation

Testing started at 3:26 pm ...
jwkTry = Failure(java.lang.RuntimeException: Unsupported jwk null)

Process finished with exit code 0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions