From 7385bf58448a9e006486cd07bfb8701b201d82a5 Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Tue, 1 Nov 2022 10:21:58 +0100 Subject: Apply suggestions from code review --- vespajlib/src/main/java/com/yahoo/collections/MethodCache.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'vespajlib/src/main/java/com') diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java index 2b8f7831a20..700f16ee519 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java @@ -36,6 +36,10 @@ public final class MethodCache { public Method get(Object object, Consumer onPut) { Pair, Method> pair = cache.get(object.getClass().getName()); + // When changing bundles, you might end up having cached the old method pointing to the old bundle. + // That will then lead to a class cast exception when invoking the wrong clone method. + // Whenever we detect a new class with the same name, we therefore drop the entire cache. + // This is also the reason for caching the pair of method and original class—not just the method. if (pair != null && pair.getFirst() != object.getClass()) { cache.clear(); pair = null; -- cgit v1.2.3