From fb9612c593c2ed9059f06b1779382507d5ae9bdf Mon Sep 17 00:00:00 2001 From: Tomas Hofman Date: Fri, 1 Nov 2024 11:23:22 +0100 Subject: [PATCH] Attempt to solve a NPE, possibly due to concurrent usage of ManifestVerifier --- .../org/jboss/set/components/ManifestVerifier.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jboss/set/components/ManifestVerifier.java b/src/main/java/org/jboss/set/components/ManifestVerifier.java index ae6a184..b96954e 100644 --- a/src/main/java/org/jboss/set/components/ManifestVerifier.java +++ b/src/main/java/org/jboss/set/components/ManifestVerifier.java @@ -13,7 +13,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -118,13 +117,11 @@ private static ArtifactCoordinate stream2Coord(Stream stream) { } static class BuildRecorder { - Map>> buildsByComponent = new HashMap<>(); + Map>> buildsByComponent = new ConcurrentHashMap<>(); void record(PncBuild.Id buildId, PncComponent component, ArtifactCoordinate artifactCoordinate) { - buildsByComponent.putIfAbsent(component, new ConcurrentHashMap<>()); - - buildsByComponent.get(component).putIfAbsent(buildId, new ConcurrentLinkedQueue<>()); - - buildsByComponent.get(component).get(buildId).add(artifactCoordinate); + Map> buildToArtifacts = buildsByComponent.computeIfAbsent(component, k -> new ConcurrentHashMap<>()); + Collection artifacts = buildToArtifacts.computeIfAbsent(buildId, k -> new ConcurrentLinkedQueue<>()); + artifacts.add(artifactCoordinate); } Collection recordedComponents() {