From 0f050d6b9299136ce9ef68bb36bef510f7749cfb Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 10 Jan 2024 15:36:17 -0600 Subject: [PATCH] CLDR-7646 TestCache concurrency issues - fix the TestCacheBundle and TestCacheResult caches to be concurrent safe --- .../java/org/unicode/cldr/test/TestCache.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java index 022370ad85b..0aa0acf72e5 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; import java.util.logging.Logger; import org.unicode.cldr.test.CheckCLDR.CheckStatus; import org.unicode.cldr.test.CheckCLDR.Options; @@ -60,12 +62,13 @@ public void check(String path, List result, String value) { */ result.clear(); Pair key = new Pair<>(path, value); - List cachedResult = pathCache.get(key); + List cachedResult = pathCache.computeIfAbsent(key, (Pair k) -> { + List l = new ArrayList(); + cc.check(k.getFirst(), file.getFullXPath(k.getFirst()), k.getSecond(), options, l); + return l; + }); if (cachedResult != null) { result.addAll(cachedResult); - } else { - cc.check(path, file.getFullXPath(path), value, options, result); - pathCache.put(key, ImmutableList.copyOf(result)); } } @@ -96,16 +99,13 @@ public List getPossibleProblems() { private String nameMatcher = ".*"; /** Get the bundle for this test */ - public TestResultBundle getBundle(CheckCLDR.Options options) { - TestResultBundle b = testResultCache.getIfPresent(options); - if (b != null) { - logger.finest(() -> this + " Bundle refvalid: " + options); - } - if (b == null) { - // ElapsedTimer et = new ElapsedTimer("New test bundle " + locale + " opt " + options); - b = new TestResultBundle(options); - // System.err.println(et.toString()); - testResultCache.put(options, b); + public TestResultBundle getBundle(final CheckCLDR.Options options) { + TestResultBundle b; + try { + b = testResultCache.get(options, () -> new TestResultBundle(options)); + } catch (ExecutionException e) { + logger.log(Level.SEVERE, e, () -> "Failed to load " + options); + throw new RuntimeException(e); } return b; }