Skip to content

Commit 6099535

Browse files
pmonksgoneall
andcommitted
Update src/main/java/org/spdx/utility/DownloadCache.java
Only construct new `ReentrantLock` if needed. Co-authored-by: Gary O'Neall <gary@sourceauditor.com> Signed-off-by: Peter Monks <pmonks@gmail.com>
1 parent f2fb507 commit 6099535

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/main/java/org/spdx/utility/DownloadCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public InputStream getUrlInputStream(final URL url, final boolean restrictRedire
219219
if (cacheEnabled) {
220220
// Per-URL critical section (to prevent cache stampede)
221221
final String normalizedUrl = normalizeURL(url);
222-
perUrlLocks.putIfAbsent(normalizedUrl, new ReentrantLock());
222+
perUrlLocks.computeIfAbsent(normalizedUrl, k -> new ReentrantLock());
223223
final Lock lock = perUrlLocks.get(normalizedUrl);
224224
lock.lock();
225225

0 commit comments

Comments
 (0)