Skip to content

Commit

Permalink
Enable running on Java 17 (#541)
Browse files Browse the repository at this point in the history
Before this path, mdoc keeps crashing with
```
[info] running (fork) mdoc.Main 
[error] java.lang.NoSuchFieldException: ucp
[error] 	at java.base/java.lang.Class.getDeclaredField(Class.java:2549)
[error] 	at mdoc.internal.CompatClassloader$.getURLs(CompatClassloader.scala:29)
```
As seen for example here
https://github.com/eikek/emil/pull/233/checks?check_run_id=3260441241#step:6:450
eikek/emil#233
  • Loading branch information
Ondra Pelech authored Aug 6, 2021
1 parent 5eaa114 commit eecf758
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [[email protected], [email protected]]
java: ['[email protected]', '[email protected]', '[email protected]']
command:
- "'++2.11.12 test'"
# Test legacy Scala versions, where reporting API changed
Expand Down
1 change: 0 additions & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
-Xmx2G
-XX:ReservedCodeCacheSize=1024m
-XX:+TieredCompilation
-XX:+CMSClassUnloadingEnabled
-Dfile.encoding=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.5.5
9 changes: 8 additions & 1 deletion mdoc/src/main/scala/mdoc/internal/CompatClassloader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ object CompatClassloader {
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)

Expand Down

0 comments on commit eecf758

Please sign in to comment.