From 98ea07dd5827a988a40a04ff33ec3787601bb2f9 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 4 Jul 2021 08:23:24 +0200 Subject: [PATCH] fix: Do not wrap runtime exceptions caused by reflected method invocation (#431) --- .../java/io/appium/uiautomator2/utils/ReflectionUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/appium/uiautomator2/utils/ReflectionUtils.java b/app/src/main/java/io/appium/uiautomator2/utils/ReflectionUtils.java index 9cd02868f..2b5967250 100644 --- a/app/src/main/java/io/appium/uiautomator2/utils/ReflectionUtils.java +++ b/app/src/main/java/io/appium/uiautomator2/utils/ReflectionUtils.java @@ -20,6 +20,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; @@ -80,8 +81,9 @@ public static void setField(final String fieldName, final Object value, final Ob public static Object invoke(final Method method, final Object object, final Object... parameters) { try { return method.invoke(object, parameters); - } catch (Exception e) { - throw new UiAutomator2Exception(String.format("Cannot invoke method %s on object %s with parameters %s", + } catch (IllegalAccessException | InvocationTargetException e) { + throw new UiAutomator2Exception(String.format( + "Cannot invoke method %s on object %s with parameters %s", method, object, Arrays.toString(parameters)), e); } }