diff options
author | jonmv <venstad@gmail.com> | 2022-10-25 21:37:42 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-10-25 21:37:42 +0200 |
commit | f9c38afb13900c8c0bd1711533b1b5bb8ce16515 (patch) | |
tree | 10a1543d67fe883f4d9b47de540cb16eda7a419a /vespajlib | |
parent | eacaf2241d1319b69c7105b2d431e1cc160c4699 (diff) |
Use string keys, but clear entries when new class has same name
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/collections/MethodCache.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java index c0beeb2da92..8773a85abe3 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java @@ -16,7 +16,7 @@ import java.util.function.Consumer; public final class MethodCache { private final String methodName; - private final CopyOnWriteHashMap<Class<?>, Method> cache = new CopyOnWriteHashMap<>(); + private final CopyOnWriteHashMap<String, Method> cache = new CopyOnWriteHashMap<>(); public MethodCache(String methodName) { this.methodName = methodName; @@ -34,13 +34,17 @@ public final class MethodCache { return get(object, null); } public Method get(Object object, Consumer<String> onPut) { - Method m = cache.get(object.getClass()); + Method m = cache.get(object.getClass().getName()); + if ( ! m.getDeclaringClass().isAssignableFrom(object.getClass())) { + cache.remove(object.getClass().getName()); + m = null; + } if (m == null) { m = lookupMethod(object); if (m != null) { if (onPut != null) onPut.accept(object.getClass().getName()); - cache.put(object.getClass(), m); + cache.put(object.getClass().getName(), m); } } return m; |