Skip to content

Commit

Permalink
Fixed #1424 variant: PackageLocationCache kept calling kpsewhich when…
Browse files Browse the repository at this point in the history
… the cache contains a null value.

- Replaced the use of 'getOrPut' by custom code using 'containsKey'. getOrPut re-evaluates the defaultValue function when the value is null, which happens when the key is absent, or when there is a key with a null-value.
- See https://youtrack.jetbrains.com/issue/KT-21392
  • Loading branch information
HannahSchellekens committed Jan 5, 2021
1 parent 5c8a4c4 commit f378cb1
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ object LatexPackageLocationCache {
*
* @param name Package name with extension.
*/
fun getPackageLocation(name: String, project: Project) = cache.getOrPut(name) {
runKpsewhich(name, project)
fun getPackageLocation(name: String, project: Project): String? {
if (cache.containsKey(name).not()) {
val path = runKpsewhich(name, project)
cache[name] = path
return path
}

return cache[name]
}

private fun runKpsewhich(arg: String, project: Project): String? = try {
Expand All @@ -36,7 +42,7 @@ object LatexPackageLocationCache {
"${LatexSdkUtil.getExecutableName("kpsewhich", project)} $arg"
}
BufferedReader(
InputStreamReader(Runtime.getRuntime().exec(command).inputStream)
InputStreamReader(Runtime.getRuntime().exec(command).inputStream)
).readLine() // Returns null if no line read.
}
catch (e: IOException) {
Expand Down

0 comments on commit f378cb1

Please sign in to comment.