diff --git a/src/main/java/hudson/remoting/JarLoaderImpl.java b/src/main/java/hudson/remoting/JarLoaderImpl.java index e15c4a949..560f97e21 100644 --- a/src/main/java/hudson/remoting/JarLoaderImpl.java +++ b/src/main/java/hudson/remoting/JarLoaderImpl.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.NotSerializableException; import java.io.OutputStream; +import java.io.UncheckedIOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; @@ -25,13 +26,10 @@ class JarLoaderImpl implements JarLoader, SerializableOnlyOverRemoting { private static final Logger LOGGER = Logger.getLogger(JarLoaderImpl.class.getName()); - @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "TODO needs triage") - private final ConcurrentMap knownJars = new ConcurrentHashMap<>(); + private static final ConcurrentMap KNOWN_JARS = new ConcurrentHashMap<>(); - @SuppressFBWarnings( - value = {"DMI_COLLECTION_OF_URLS", "SE_BAD_FIELD"}, - justification = "TODO needs triage") - private final ConcurrentMap checksums = new ConcurrentHashMap<>(); + @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", justification = "TODO needs triage") + private static final ConcurrentMap CHECKSUMS = new ConcurrentHashMap<>(); @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "TODO needs triage") private final Set presentOnRemote = Collections.synchronizedSet(new HashSet<>()); @@ -42,7 +40,7 @@ class JarLoaderImpl implements JarLoader, SerializableOnlyOverRemoting { justification = "This is only used for managing the jar cache as files, not URLs.") public void writeJarTo(long sum1, long sum2, OutputStream sink) throws IOException, InterruptedException { Checksum k = new Checksum(sum1, sum2); - URL url = knownJars.get(k); + URL url = KNOWN_JARS.get(k); if (url == null) { throw new IOException("Unadvertised jar file " + k); } @@ -93,16 +91,19 @@ public void notifyJarPresence(long[] sums) { * Obtains the checksum for the jar at the specified URL. */ public Checksum calcChecksum(URL jar) throws IOException { - Checksum v = checksums.get(jar); // cache hit - if (v != null) { - return v; + try { + return CHECKSUMS.computeIfAbsent(jar, u -> { + try { + Checksum c = Checksum.forURL(u); + KNOWN_JARS.put(c, u); + return c; + } catch (IOException e) { + throw new UncheckedIOException(e); + } + }); + } catch (UncheckedIOException e) { + throw e.getCause(); } - - v = Checksum.forURL(jar); - - knownJars.put(v, jar); - checksums.put(jar, v); - return v; } /**