From 405a60365c774aeee98918cb361d807e939126d8 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Mon, 28 Feb 2022 14:51:26 +0800 Subject: [PATCH] Fix hashCode crash --- .../blackreflection/BlackReflection.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java index e7752e5..19566c1 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java +++ b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java @@ -45,24 +45,9 @@ public class BlackReflection { public static T create(Class clazz, final Object caller, boolean withException) { try { - if (!withException) { - if (caller == null) { - Object o = sProxyCache.get(clazz); - if (o != null) { - return (T) o; - } - } - else { - Map, Object> callerClassMap = sCallerProxyCache.get(caller); - if (callerClassMap != null) { - Object o = callerClassMap.get(clazz); - if (o != null) { - return (T) o; - } - } - } - } - + T proxy = getProxy(clazz, caller, withException); + if (proxy != null) + return proxy; final WeakReference weakCaller = caller == null ? null : new WeakReference<>(caller); final Class aClass = getClassNameByBlackClass(clazz); @@ -194,6 +179,30 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl return null; } + private static T getProxy(Class clazz, final Object caller, boolean withException) { + try { + if (!withException) { + if (caller == null) { + Object o = sProxyCache.get(clazz); + if (o != null) { + return (T) o; + } + } + else { + Map, Object> callerClassMap = sCallerProxyCache.get(caller); + if (callerClassMap != null) { + Object o = callerClassMap.get(clazz); + if (o != null) { + return (T) o; + } + } + } + } + } catch (Throwable ignore) { + } + return null; + } + private static Class[] getParamClass(Method method) throws Throwable { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Class[] parameterTypes = method.getParameterTypes();