Skip to content

Commit e79ac4d

Browse files
committed
KTNB-1041: Fix resource loading
1 parent 43f3bbe commit e79ac4d

File tree

1 file changed

+7
-1
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io

1 file changed

+7
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ internal val formatter = DataFrameFormatter(
7777
internal fun getResources(vararg resource: String) = resource.joinToString(separator = "\n") { getResourceText(it) }
7878

7979
internal fun getResourceText(resource: String, vararg replacement: Pair<String, Any>): String {
80-
val res = DataFrame::class.java.getResourceAsStream(resource) ?: error("Resource '$resource' not found")
80+
/**
81+
* The choice of loader is crucial here: it should always be a class loaded by the same class loader as the resource we load.
82+
* I.e. [DataFrame] isn't a good fit because it might be loaded by Kotlin IDEA plugin (because Kotlin plugin
83+
* loads DataFrame compiler plugin), and plugin's classloader knows nothing about the resources.
84+
*/
85+
val loader = HtmlContent::class.java
86+
val res = loader.getResourceAsStream(resource) ?: error("Resource '$resource' not found")
8187
var template = InputStreamReader(res).readText()
8288
replacement.forEach {
8389
template = template.replace(it.first, it.second.toString())

0 commit comments

Comments
 (0)