1- From 6f5f186a640e0d4ef0bff4d18dbb36f969dc5b16 Mon Sep 17 00:00:00 2001
1+ From 64b33dba002ec2b661f1e7cc8a1a6a1667e751d8 Mon Sep 17 00:00:00 2001
22From: Akash Yadav <akashyadav@appdevforall.org>
33Date: Thu, 26 Mar 2026 14:12:33 +0530
44Subject: [PATCH 1/9] fix: use application class loader to find jrt:/ file
@@ -9,24 +9,54 @@ To ensure Kotlin's CoreJrtFileSystem can find the jrt:/ file system, we need to
99use the application class loader. This makes it possible for the consuming application
1010to provide its own implementation of the jrt:/ file system (as we do in Code On the Go).
1111
12+ The isAtLeastJava9() branch is removed rather than kept: androidJavaVersion() reports
13+ Java 8 for SDK_INT < 31, so on API <= 30 the old code took the URLClassLoader(jrt-fs.jar)
14+ fallback, which cannot work on ART and broke LSP initialization. With the provider always
15+ resolved from the application class loader there is no version-dependent path left.
16+
17+ The jrt-fs.jar existence check in globalJrtFsCache goes away with it. The bundled JDK home
18+ always contains lib/jrt-fs.jar, so the check never failed, and isModularJdk() still guards
19+ JDK root configuration in jvmArguments.kt and JvmContentRoots.kt.
20+
21+ See https://github.com/appdevforall/CodeOnTheGo/issues/1334
22+
23+ Co-authored-by: Wadamzmail <alksndrmetwakil@gmail.com>
1224Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
1325---
14- .../org/ jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt | 2 + -
15- 1 file changed, 1 insertion (+), 1 deletion (-)
26+ .../jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt | 7 ++++-- -
27+ 1 file changed, 4 insertions (+), 3 deletions (-)
1628
1729diff --git a/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt b/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt
18- index 335a4db84c47..c399ca5bca10 100644
30+ index 335a4db84c47..566e30e2b793 100644
1931--- a/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt
2032+++ b/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt
21- @@ -83,7 +83,7 @@ class CoreJrtFileSystem : DeprecatedVirtualFileSystem() {
22- if (isAtLeastJava9()) {
33+ @@ -73,14 +73,14 @@ class CoreJrtFileSystem : DeprecatedVirtualFileSystem() {
34+
35+ private val globalJrtFsCache = ConcurrentFactoryMap.createMap<String, FileSystem?> { jdkHomePath ->
36+ val jdkHome = File(jdkHomePath)
37+ - val jrtFsJar = loadJrtFsJar(jdkHome) ?: return@createMap null
38+ + /*val jrtFsJar = loadJrtFsJar(jdkHome) ?: return@createMap null*/
39+ val rootUri = URI.create(StandardFileSystems.JRT_PROTOCOL + ":/")
40+ /*
41+ The ClassLoader, that was used to load JRT FS Provider actually lives as long as current thread due to ThreadLocal leak in jrt-fs,
42+ See https://bugs.openjdk.java.net/browse/JDK-8260621
43+ So that cache allows us to avoid creating too many classloaders for same JDK and reduce severity of that leak
44+ */
45+ - if (isAtLeastJava9()) {
46+ + /*if (isAtLeastJava9()) {
2347 // If the runtime JDK is set to 9+ it has JrtFileSystemProvider,
2448 // but to load proper jrt-fs (one that is pointed by jdkHome) we should provide "java.home" path
25- - FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
26- + FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath), CoreJrtFileSystem::class.java.classLoader)
27- } else {
28- val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
29- // If the runtime JDK is set to <9, there are no JrtFileSystemProvider,
49+ FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
50+ @@ -90,7 +90,8 @@ class CoreJrtFileSystem : DeprecatedVirtualFileSystem() {
51+ // we should create classloader with jrt-fs.jar, and DO NOT NEED to pass "java.home" path,
52+ // as otherwise it will incur additional classloader creation
53+ FileSystems.newFileSystem(rootUri, emptyMap<String, Nothing>(), classLoader)
54+ - }
55+ + }*/
56+ + FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath), CoreJrtFileSystem::class.java.classLoader)
57+ }
58+ }
59+ }
3060- -
31612.54.0
3262
0 commit comments