Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
From 6f5f186a640e0d4ef0bff4d18dbb36f969dc5b16 Mon Sep 17 00:00:00 2001
From a20de7ca03c18f2ff8eb79380181133d349c80ed Mon Sep 17 00:00:00 2001
From: Akash Yadav <akashyadav@appdevforall.org>
Date: Thu, 26 Mar 2026 14:12:33 +0530
Subject: [PATCH 1/9] fix: use application class loader to find jrt:/ file
system
Date: Sat, 25 Jul 2026 17:06:11 +0200
Subject: [PATCH 1/9] fix: use application class loader to find jrt:/ file system

The JRT file system is not available on Android. It needs to be part of the application.
To ensure Kotlin's CoreJrtFileSystem can find the jrt:/ file system, we need to make it
use the application class loader. This makes it possible for the consuming application
to provide its own implementation of the jrt:/ file system (as we do in Code On the Go).

Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Co-authored-by: Wadamzmail <alksndrmetwakil@gmail.com>
---
.../org/jetbrains/kotlin/cli/jvm/modules/CoreJrtFileSystem.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
.../cli/jvm/modules/CoreJrtFileSystem.kt | 30 ++++++++-----------
1 file changed, 12 insertions(+), 18 deletions(-)

diff --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
index 335a4db84c47..c399ca5bca10 100644
index 335a4db..3e07be2 100644
--- 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
@@ -83,7 +83,7 @@ class CoreJrtFileSystem : DeprecatedVirtualFileSystem() {
if (isAtLeastJava9()) {
// If the runtime JDK is set to 9+ it has JrtFileSystemProvider,
// but to load proper jrt-fs (one that is pointed by jdkHome) we should provide "java.home" path
@@ -23,7 +23,6 @@ import com.intellij.util.containers.ConcurrentFactoryMap
import com.intellij.util.io.URLUtil
import java.io.File
import java.net.URI
-import java.net.URLClassLoader
import java.nio.file.FileSystem
import java.nio.file.FileSystems

@@ -73,24 +72,19 @@ class CoreJrtFileSystem : DeprecatedVirtualFileSystem() {

private val globalJrtFsCache = ConcurrentFactoryMap.createMap<String, FileSystem?> { jdkHomePath ->
val jdkHome = File(jdkHomePath)
- val jrtFsJar = loadJrtFsJar(jdkHome) ?: return@createMap null
val rootUri = URI.create(StandardFileSystems.JRT_PROTOCOL + ":/")
+
/*
- The ClassLoader, that was used to load JRT FS Provider actually lives as long as current thread due to ThreadLocal leak in jrt-fs,
- See https://bugs.openjdk.java.net/browse/JDK-8260621
- So that cache allows us to avoid creating too many classloaders for same JDK and reduce severity of that leak
- */
- if (isAtLeastJava9()) {
- // If the runtime JDK is set to 9+ it has JrtFileSystemProvider,
- // but to load proper jrt-fs (one that is pointed by jdkHome) we should provide "java.home" path
- FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
+ FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath), CoreJrtFileSystem::class.java.classLoader)
} else {
val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
// If the runtime JDK is set to <9, there are no JrtFileSystemProvider,
- } else {
- val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
- // If the runtime JDK is set to <9, there are no JrtFileSystemProvider,
- // we should create classloader with jrt-fs.jar, and DO NOT NEED to pass "java.home" path,
- // as otherwise it will incur additional classloader creation
- FileSystems.newFileSystem(rootUri, emptyMap<String, Nothing>(), classLoader)
- }
+ * CodeOnTheGo bundles its own jrt-fs implementation inside the APK.
+ * Therefore, we do not need to check the runtime Java version here.
+ * Always resolve the JRT FileSystemProvider from the application's ClassLoader,
+ * using the bundled implementation regardless of the Android or Java runtime.
+ */
+ FileSystems.newFileSystem(
+ rootUri,
+ mapOf("java.home" to jdkHome.absolutePath),
+ CoreJrtFileSystem::class.java.classLoader
+ )
}
}
-}
+}
\ No newline at end of file
--
2.54.0
2.52.0

Loading