Fix cache deadlock in `XposedHelpers.java` (#1723)

This commit is contained in:
清茶 2022-02-25 18:37:06 +08:00 committed by GitHub
parent 583be18a7b
commit 3fdc4e51c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -520,16 +520,16 @@ public final class XposedHelpers {
* @throws NoSuchMethodError In case no suitable method was found.
*/
public static Method findMethodBestMatch(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
var key = new MemberCacheKey.Method(clazz, methodName, parameterTypes, false);
return methodCache.computeIfAbsent(key, k -> {
// find the exact matching method first
try {
return Optional.of(findMethodExact(k.clazz, k.name, k.parameters));
return findMethodExact(clazz, methodName, parameterTypes);
} catch (NoSuchMethodError ignored) {
}
// then find the best match
var key = new MemberCacheKey.Method(clazz, methodName, parameterTypes, false);
return methodCache.computeIfAbsent(key, k -> {
Method bestMatch = null;
Class<?> clz = k.clazz;
boolean considerPrivateMethods = true;
@ -712,7 +712,7 @@ public final class XposedHelpers {
return constructorCache.computeIfAbsent(key, k -> {
try {
Constructor<?> constructor = clazz.getDeclaredConstructor(parameterTypes);
Constructor<?> constructor = k.clazz.getDeclaredConstructor(k.parameters);
constructor.setAccessible(true);
return Optional.of(constructor);
} catch (NoSuchMethodException e) {
@ -749,16 +749,16 @@ public final class XposedHelpers {
* <p>See {@link #findMethodBestMatch(Class, String, Class...)} for details.
*/
public static Constructor<?> findConstructorBestMatch(Class<?> clazz, Class<?>... parameterTypes) {
var key = new MemberCacheKey.Constructor(clazz, parameterTypes, false);
return constructorCache.computeIfAbsent(key, k -> {
// find the exact matching constructor first
try {
return Optional.of(findConstructorExact(k.clazz, k.parameters));
return findConstructorExact(clazz, parameterTypes);
} catch (NoSuchMethodError ignored) {
}
// then find the best match
var key = new MemberCacheKey.Constructor(clazz, parameterTypes, false);
return constructorCache.computeIfAbsent(key, k -> {
Constructor<?> bestMatch = null;
Constructor<?>[] constructors = k.clazz.getDeclaredConstructors();
for (Constructor<?> constructor : constructors) {