diff options
Diffstat (limited to 'sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java')
-rw-r--r-- | sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java b/sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java index 30ee4f563..1c6d8c19c 100644 --- a/sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java +++ b/sandbox/src/main/java/org/robolectric/internal/bytecode/ShadowWrangler.java @@ -23,7 +23,6 @@ import javax.annotation.Nonnull; import javax.annotation.Priority; import org.robolectric.annotation.RealObject; import org.robolectric.annotation.ReflectorObject; -import org.robolectric.sandbox.NativeMethodNotFoundException; import org.robolectric.sandbox.ShadowMatcher; import org.robolectric.util.Function; import org.robolectric.util.PerfStatsCollector; @@ -183,21 +182,7 @@ public class ShadowWrangler implements ClassHandler { } else { RobolectricInternals.performStaticInitialization(clazz); } - } catch (InvocationTargetException e) { - // Note: target exception originates from the sandbox classloader. - // "instanceof" does not check class equality across classloaders (since they differ). - // A simple workaround is to check the class FQCN instead. - String nativeMethodNotFoundException = NativeMethodNotFoundException.class.getName(); - - for (Throwable t = e.getTargetException(); t != null; ) { - if (nativeMethodNotFoundException.equals(t.getClass().getName())) { - throw (RuntimeException) t; - } - - t = t.getCause(); - } - throw new RuntimeException(e); - } catch (IllegalAccessException e) { + } catch (InvocationTargetException | IllegalAccessException e) { throw new RuntimeException(e); } } @@ -210,7 +195,11 @@ public class ShadowWrangler implements ClassHandler { @SuppressWarnings({"ReferenceEquality"}) @Override public MethodHandle findShadowMethodHandle( - Class<?> definingClass, String name, MethodType methodType, boolean isStatic) + Class<?> definingClass, + String name, + MethodType methodType, + boolean isStatic, + boolean isNative) throws IllegalAccessException { return PerfStatsCollector.getInstance() .measure( @@ -222,6 +211,18 @@ public class ShadowWrangler implements ClassHandler { Method shadowMethod = pickShadowMethod(definingClass, name, paramTypes); if (shadowMethod == CALL_REAL_CODE) { + ShadowInfo shadowInfo = getExactShadowInfo(definingClass); + if (isNative && shadowInfo != null && shadowInfo.callNativeMethodsByDefault) { + try { + Method method = + definingClass.getDeclaredMethod( + ShadowConstants.ROBO_PREFIX + name + "$nativeBinding", paramTypes); + method.setAccessible(true); + return LOOKUP.unreflect(method); + } catch (NoSuchMethodException e) { + throw new LinkageError("Missing native binding method", e); + } + } return null; } else if (shadowMethod == DO_NOTHING_METHOD) { return DO_NOTHING; |