From 84093cfa57a7be6733e464b723924d59a15c59fe Mon Sep 17 00:00:00 2001 From: Bernd Engelhardt Date: Thu, 8 Oct 2026 20:38:52 +0200 Subject: [PATCH] Do not return a null name when the name cache is cleared concurrently getASAtom looked up a dynamic name with containsKey followed by get. Since clearCache() can empty the cache at runtime, a clear on another thread between the two calls made getASAtom return null for a non-null name. Read the cache with a single get and fall back to creating the atom when the result is null. The predefined-name lookup is unchanged; that map is never cleared. --- src/main/java/org/verapdf/as/ASAtom.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/verapdf/as/ASAtom.java b/src/main/java/org/verapdf/as/ASAtom.java index f19a7ab9..c15b79a8 100644 --- a/src/main/java/org/verapdf/as/ASAtom.java +++ b/src/main/java/org/verapdf/as/ASAtom.java @@ -758,8 +758,10 @@ public static ASAtom getASAtom(String value) { if (PREDEFINED_PDF_NAMES.containsKey(value)) { return PREDEFINED_PDF_NAMES.get(value); } - if (CACHED_PDF_NAMES.containsKey(value)) { - return CACHED_PDF_NAMES.get(value); + // A single lookup: clearCache() may run on another thread between a containsKey and a get. + ASAtom cached = CACHED_PDF_NAMES.get(value); + if (cached != null) { + return cached; } // The constructor is the single caching point; it honours the configured cache limit. return new ASAtom(value, false);