From 2f9e766ec269e4e4dd8ddb0f92d915366110af6d Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 1 Oct 2012 23:36:18 +0200 Subject: fixes a bug in a weak cache in runtime reflection Entries in SynchronizedTypes.uniques could previously be garbage collected in-between a successful call to contains and an actual cache lookup. The patch could be a one-liner, but I don't want to use HOFs in this function, whose prototype is a hotspot in the compiler. Also the fix doesn't touch scalac in any way. It only applies to reflective universes that provide runtime reflection functionality. --- src/reflect/scala/reflect/runtime/SynchronizedTypes.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala index b9b140a2fd..9b4d8d1d48 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala @@ -24,7 +24,8 @@ trait SynchronizedTypes extends internal.Types { self: SymbolTable => // i.e. they have their caches cleaned up automatically on per-run basis, // therefore they should use vanilla uniques, which are faster if (!isCompilerUniverse) { - val result = if (uniques contains tp) uniques(tp).get else null + val inCache = uniques get tp + val result = if (inCache.isDefined) inCache.get.get else null if (result ne null) result.asInstanceOf[T] else { uniques(tp) = new WeakReference(tp) -- cgit v1.2.3