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();