Skip to content

Commit d051441

Browse files
committed
Fixed recursive update on concurrent hash map
1 parent 9fa1b89 commit d051441

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/StructureRegistry.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
8181
): StructureTemplate {
8282
updateFileWatcher()
8383

84-
return computeIfAbsent(relativePath.pathString.lowercase()) {
85-
loadFileAndCreate(relativePath, convert)
86-
}
84+
val struct = loadFileAndCreate(relativePath, convert)
85+
putIfAbsent(relativePath.pathString.lowercase(), struct)
86+
87+
return struct
8788
}
8889

8990
/**
@@ -101,9 +102,8 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
101102
when (event.kind()) {
102103
ENTRY_DELETE -> remove(newPath.pathString)
103104
ENTRY_CREATE -> {
104-
computeIfAbsent(newPath.pathString) {
105-
loadStructureByRelativePath(newPath, convert = true)
106-
}
105+
putIfAbsent(newPath.pathString,
106+
loadStructureByRelativePath(newPath, convert = true))
107107
}
108108
}
109109

@@ -186,7 +186,7 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
186186
.sortedBy { it.extension.length } // Don’t walk lexicographically -Constructor
187187
.distinctBy { it.nameWithoutExtension }
188188
.forEach { loadStructureByRelativePath(structure.relativize(it)) }
189-
}.onFailure { LOG.warn(it.message) }
189+
}.onFailure { LOG.warn("Error while loading a structure:", it) }
190190

191191
return "Loaded $size structure templates"
192192
}

0 commit comments

Comments
 (0)