diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67c0fe145..af3180477 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,16 @@ jobs: java-version: adopt@1.11 - run: sbt ci-213 + jdk17_213: + name: JDK117/scala_2.13 tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: olafurpg/setup-scala@v13 + with: + java-version: 17 + - run: sbt ci-213 + windows_213: name: Windows/scala_2.13 tests runs-on: windows-latest diff --git a/scalafix-reflect/src/main/scala/scalafix/internal/reflect/ClasspathOps.scala b/scalafix-reflect/src/main/scala/scalafix/internal/reflect/ClasspathOps.scala index 7b3e29ffe..ec2ca67e4 100644 --- a/scalafix-reflect/src/main/scala/scalafix/internal/reflect/ClasspathOps.scala +++ b/scalafix-reflect/src/main/scala/scalafix/internal/reflect/ClasspathOps.scala @@ -129,7 +129,14 @@ object ClasspathOps { val unsafe = field.get(null).asInstanceOf[Unsafe] // jdk.internal.loader.ClassLoaders.AppClassLoader.ucp - val ucpField = classLoader.getClass().getDeclaredField("ucp") + val ucpField = { + if ( + System.getProperty("java.version").split("(\\.|-)")(0).toInt >= 16 + ) { + // the `ucp` field is not in `AppClassLoader` anymore, but in `BuiltinClassLoader` + classLoader.getClass().getSuperclass() + } else classLoader.getClass() + }.getDeclaredField("ucp") val ucpFieldOffset: Long = unsafe.objectFieldOffset(ucpField) val ucpObject = unsafe.getObject(classLoader, ucpFieldOffset) diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/interfaces/ScalafixSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/interfaces/ScalafixSuite.scala index 2d769a8a3..811d5419f 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/interfaces/ScalafixSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/interfaces/ScalafixSuite.scala @@ -99,11 +99,13 @@ class ScalafixSuite extends AnyFunSuite { // 2.11(.12) triggers `java.lang.NoClassDefFoundError: javax/tools/DiagnosticListener` on Java11. // See https://github.com/scala/bug/issues/10603. - val isJava11: Boolean = Option(System.getProperty("java.version")) - .getOrElse("") - .startsWith("11") + val javaVersionOpt: Option[String] = Option( + System.getProperty("java.version") + ) + val isJava11: Boolean = javaVersionOpt.getOrElse("").startsWith("11") + val isJava17: Boolean = javaVersionOpt.getOrElse("").startsWith("17") val scalaBinaryVersionsToRun: Set[String] = - if (isJava11) supportedScalaBinaryVersions - "2.11" + if (isJava11 || isJava17) supportedScalaBinaryVersions - "2.11" else supportedScalaBinaryVersions scalaBinaryVersionsToRun.map { scalaBinaryVersion =>