From 8b0bcc6fcf5b5d3dcab08a27b4a0b627aa1afea1 Mon Sep 17 00:00:00 2001 From: Matt Dziuban Date: Sat, 7 Jun 2025 23:44:29 -0400 Subject: [PATCH] Revert use of WeakReferences for SbtUpdateReport cached values --- .../scala/lmcoursier/internal/SbtUpdateReport.scala | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lm-coursier/src/main/scala/lmcoursier/internal/SbtUpdateReport.scala b/lm-coursier/src/main/scala/lmcoursier/internal/SbtUpdateReport.scala index d97492911..649e24da0 100644 --- a/lm-coursier/src/main/scala/lmcoursier/internal/SbtUpdateReport.scala +++ b/lm-coursier/src/main/scala/lmcoursier/internal/SbtUpdateReport.scala @@ -1,7 +1,6 @@ package lmcoursier.internal import java.io.File -import java.lang.ref.WeakReference import java.util.{ Collections, GregorianCalendar, WeakHashMap } import coursier.cache.CacheUrl import coursier.{ Attributes, Dependency, Module, Project, Resolution } @@ -18,16 +17,16 @@ private[internal] object SbtUpdateReport { private def caching[K, V](f: K => V): K => V = { - val cache = Collections.synchronizedMap(new WeakHashMap[K, WeakReference[V]]) + val cache = Collections.synchronizedMap(new WeakHashMap[K, V]) key => val previousValueOpt = Option(cache.get(key)) - previousValueOpt.fold { + previousValueOpt.getOrElse { val value = f(key) - val concurrentValueOpt = Option(cache.putIfAbsent(key, new WeakReference(value))) - concurrentValueOpt.fold(value)(_.get()) - }(_.get()) + val concurrentValueOpt = Option(cache.putIfAbsent(key, value)) + concurrentValueOpt.getOrElse(value) + } } private def infoProperties(project: Project): Seq[(String, String)] =