summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Fischer <ntfschr@chromium.org>2018-04-02 18:14:16 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-04-02 18:14:16 +0000
commitcaafe5199285cfd7f5e9a3e3c36833b2fba4d0c8 (patch)
treecc9e5433ecb65a9beaf1d1f02d435ddb0d784ad0
parent791da533c572050f7ba628d9c7238911ab2a039f (diff)
parent8acd7ffa7eae1e72aa4884ed6ef921c6b812f71c (diff)
downloadwebview_support_interfaces-caafe5199285cfd7f5e9a3e3c36833b2fba4d0c8.tar.gz
AW: use correct ClassLoader in dupeMethod
am: 8acd7ffa7e Change-Id: I155fed62d9e5f8a9aa14310825b92280128c5318
-rw-r--r--src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java
index 5a772c5..51c78ed 100644
--- a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java
+++ b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java
@@ -16,13 +16,14 @@ import java.lang.reflect.Proxy;
*/
public class BoundaryInterfaceReflectionUtil {
/**
- * Utility method for fetching a method from the current classloader, with the same signature
+ * Utility method for fetching a method from {@param delegateLoader}, with the same signature
* (package + class + method name + parameters) as a given method defined in another
* classloader.
*/
- public static Method dupeMethod(Method method)
+ public static Method dupeMethod(Method method, ClassLoader delegateLoader)
throws ClassNotFoundException, NoSuchMethodException {
- Class<?> declaringClass = Class.forName(method.getDeclaringClass().getName());
+ Class<?> declaringClass =
+ Class.forName(method.getDeclaringClass().getName(), true, delegateLoader);
Class[] otherSideParameterClasses = method.getParameterTypes();
Class[] parameterClasses = new Class[otherSideParameterClasses.length];
for (int n = 0; n < parameterClasses.length; n++) {
@@ -30,7 +31,9 @@ public class BoundaryInterfaceReflectionUtil {
// Primitive classes are shared between the classloaders - so we can use the same
// primitive class declarations on either side. Non-primitive classes must be looked up
// by name.
- parameterClasses[n] = clazz.isPrimitive() ? clazz : Class.forName(clazz.getName());
+ parameterClasses[n] = clazz.isPrimitive()
+ ? clazz
+ : Class.forName(clazz.getName(), true, delegateLoader);
}
return declaringClass.getDeclaredMethod(method.getName(), parameterClasses);
}
@@ -53,11 +56,12 @@ public class BoundaryInterfaceReflectionUtil {
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static InvocationHandler createInvocationHandlerFor(final Object delegate) {
+ final ClassLoader delegateLoader = delegate.getClass().getClassLoader();
return new InvocationHandler() {
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
try {
- return dupeMethod(method).invoke(delegate, objects);
+ return dupeMethod(method, delegateLoader).invoke(delegate, objects);
} catch (InvocationTargetException e) {
// If something went wrong, ensure we throw the original exception.
throw e.getTargetException();