Skip to content

Commit 405a603

Browse files
committed
Fix hashCode crash
1 parent f68b4d3 commit 405a603

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java

+27-18
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,9 @@ public class BlackReflection {
4545

4646
public static <T> T create(Class<T> clazz, final Object caller, boolean withException) {
4747
try {
48-
if (!withException) {
49-
if (caller == null) {
50-
Object o = sProxyCache.get(clazz);
51-
if (o != null) {
52-
return (T) o;
53-
}
54-
}
55-
else {
56-
Map<Class<?>, Object> callerClassMap = sCallerProxyCache.get(caller);
57-
if (callerClassMap != null) {
58-
Object o = callerClassMap.get(clazz);
59-
if (o != null) {
60-
return (T) o;
61-
}
62-
}
63-
}
64-
}
65-
48+
T proxy = getProxy(clazz, caller, withException);
49+
if (proxy != null)
50+
return proxy;
6651
final WeakReference<Object> weakCaller = caller == null ? null : new WeakReference<>(caller);
6752

6853
final Class<?> aClass = getClassNameByBlackClass(clazz);
@@ -194,6 +179,30 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
194179
return null;
195180
}
196181

182+
private static <T> T getProxy(Class<T> clazz, final Object caller, boolean withException) {
183+
try {
184+
if (!withException) {
185+
if (caller == null) {
186+
Object o = sProxyCache.get(clazz);
187+
if (o != null) {
188+
return (T) o;
189+
}
190+
}
191+
else {
192+
Map<Class<?>, Object> callerClassMap = sCallerProxyCache.get(caller);
193+
if (callerClassMap != null) {
194+
Object o = callerClassMap.get(clazz);
195+
if (o != null) {
196+
return (T) o;
197+
}
198+
}
199+
}
200+
}
201+
} catch (Throwable ignore) {
202+
}
203+
return null;
204+
}
205+
197206
private static Class<?>[] getParamClass(Method method) throws Throwable {
198207
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
199208
Class<?>[] parameterTypes = method.getParameterTypes();

0 commit comments

Comments
 (0)