diff --git a/src/main/java/org/javarosa/core/model/ComparisonExpressionCacheFilterStrategy.java b/src/main/java/org/javarosa/core/model/ComparisonExpressionCacheFilterStrategy.java index a1a1cb39a..d6d266eeb 100644 --- a/src/main/java/org/javarosa/core/model/ComparisonExpressionCacheFilterStrategy.java +++ b/src/main/java/org/javarosa/core/model/ComparisonExpressionCacheFilterStrategy.java @@ -10,9 +10,9 @@ import org.javarosa.xpath.expr.XPathExpression; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; /** @@ -21,7 +21,7 @@ */ public class ComparisonExpressionCacheFilterStrategy implements FilterStrategy { - private final Map> cachedEvaluations = new HashMap<>(); + private final Map> cachedEvaluations = new ConcurrentHashMap<>(); @NotNull @Override @@ -56,7 +56,10 @@ public List filter(@NotNull DataInstance sourceInstance, @NotNull } } - private List getCachedEvaluations(@NotNull Supplier> next, String key) { + /** + * Synchronized to prevent two or more threads from modifying {@link #cachedEvaluations} at once + */ + private synchronized List getCachedEvaluations(@NotNull Supplier> next, String key) { if (cachedEvaluations.containsKey(key)) { return cachedEvaluations.get(key); } else {