diff options
author | Nate Fischer <ntfschr@chromium.org> | 2018-03-29 21:36:13 +0000 |
---|---|---|
committer | Nate Fischer <ntfschr@google.com> | 2018-03-29 15:26:06 -0700 |
commit | 8acd7ffa7eae1e72aa4884ed6ef921c6b812f71c (patch) | |
tree | cc9e5433ecb65a9beaf1d1f02d435ddb0d784ad0 | |
parent | c0f2da484a7b7b814b9fb939a101fc9bbcba9a43 (diff) | |
download | webview_support_interfaces-8acd7ffa7eae1e72aa4884ed6ef921c6b812f71c.tar.gz |
AW: use correct ClassLoader in dupeMethodandroid-9.0.0_r47android-9.0.0_r46android-9.0.0_r45android-9.0.0_r44android-9.0.0_r43android-9.0.0_r42android-9.0.0_r41android-9.0.0_r40android-9.0.0_r39android-9.0.0_r38android-9.0.0_r37android-9.0.0_r36android-9.0.0_r35android-9.0.0_r34android-9.0.0_r33android-9.0.0_r32android-9.0.0_r31android-9.0.0_r30android-9.0.0_r22android-9.0.0_r21android-9.0.0_r20android-9.0.0_r19android-9.0.0_r16android-9.0.0_r12android-9.0.0_r11pie-qpr3-s1-releasepie-qpr3-releasepie-qpr3-b-releasepie-qpr2-releasepie-qpr1-s3-releasepie-qpr1-s2-releasepie-qpr1-s1-releasepie-qpr1-releasepie-dr1-releasepie-dr1-devpie-devpie-b4s4-releasepie-b4s4-dev
This fixes an issue with the support library where we would sometimes
create an InvocationHandler and look up methods using the wrong
ClassLoader. This ensures we always use the correct ClassLoader.
dupeMethod() is only used here, so it's safe to change the signature.
See the crbug for more information.
Bug: 826988
Test: Manual, did this in my demo CL at http://crrev/c/965883
Change-Id: I7ca7bb90aec81a6a30ce4d6393cf40ee54d40c19
Reviewed-on: https://chromium-review.googlesource.com/985631
Reviewed-by: Richard Coles <torne@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#546961}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: c6aed4c0fe3d8eeb3ae7f2bdd32cc6433cdf929c
-rw-r--r-- | src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java | 14 |
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(); |