Skip to content

Commit

Permalink
Fix thread-safety bug in Obj.getAllKeys (#217)
Browse files Browse the repository at this point in the history
This PR fixes a thread-safety bug in Val.obj.getAllKeys, similar to the
previous fix in #136. It
looks like this particular site was overlooked in that earlier PR.

I spotted this potential issue while reading through the code, not via
actual use.
  • Loading branch information
JoshRosen authored Nov 26, 2024
1 parent 0fff9f9 commit 9f56e1f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ object Val{

private def getAllKeys = {
if(allKeys == null) {
allKeys = new util.LinkedHashMap[String, java.lang.Boolean]
val allKeys = new util.LinkedHashMap[String, java.lang.Boolean]
gatherKeys(allKeys)
// Only assign to field after initialization is complete to allow unsynchronized multi-threaded use:
this.allKeys = allKeys
}
allKeys
}
Expand Down

0 comments on commit 9f56e1f

Please sign in to comment.