From 33628f5ebb84ae2ab750ff2cf5710e587cf01252 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Mon, 21 Mar 2022 22:17:19 +0800 Subject: [PATCH] Fix Cache bug --- .../blackreflection/BlackReflection.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java index fe97753..4156198 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java +++ b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java @@ -163,15 +163,17 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl } }); - if (caller == null) { - sProxyCache.put(clazz, o); - } else { - Map, Object> callerClassMap = sCallerProxyCache.get(caller); - if (callerClassMap == null) { - callerClassMap = new HashMap<>(); - sCallerProxyCache.put(caller, callerClassMap); + if (CACHE) { + if (caller == null) { + sProxyCache.put(clazz, o); + } else { + Map, Object> callerClassMap = sCallerProxyCache.get(caller); + if (callerClassMap == null) { + callerClassMap = new HashMap<>(); + sCallerProxyCache.put(caller, callerClassMap); + } + callerClassMap.put(clazz, o); } - callerClassMap.put(clazz, o); } return (T) o; } catch (ClassNotFoundException e) {