From 452e926ec8c9b81038b490ed653e895a58c8ba6f Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Thu, 12 Jun 2025 14:16:19 +0200 Subject: [PATCH 1/2] KTNB-1041: Fix resource loading --- .../kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt index 2674e6c5bd..3df5b464ce 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt @@ -77,7 +77,13 @@ internal val formatter = DataFrameFormatter( internal fun getResources(vararg resource: String) = resource.joinToString(separator = "\n") { getResourceText(it) } internal fun getResourceText(resource: String, vararg replacement: Pair): String { - val res = DataFrame::class.java.getResourceAsStream(resource) ?: error("Resource '$resource' not found") + /** + * The choice of loader is crucial here: it should always be a class loaded by the same class loader as the resource we load. + * I.e. [DataFrame] isn't a good fit because it might be loaded by Kotlin IDEA plugin (because Kotlin plugin + * loads DataFrame compiler plugin), and plugin's classloader knows nothing about the resources. + */ + val loader = HtmlContent::class.java + val res = loader.getResourceAsStream(resource) ?: error("Resource '$resource' not found") var template = InputStreamReader(res).readText() replacement.forEach { template = template.replace(it.first, it.second.toString()) From 4b54e93b410125113f8da5f5b449168107673f94 Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Thu, 12 Jun 2025 14:23:00 +0200 Subject: [PATCH 2/2] KTNB-1041: Better diagnostic message --- .../src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt index 3df5b464ce..87176ca7e4 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt @@ -83,7 +83,8 @@ internal fun getResourceText(resource: String, vararg replacement: Pair