diff options
author | Minghao Li <lmh463896910@gmail.com> | 2024-02-23 07:05:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 15:05:55 -0800 |
commit | 08b72cb1ecc65b8ebb23c433dbe4fd45c8ac95d9 (patch) | |
tree | 28a6853c34e61c6331bdcaf1ebddfa9883a1e9c2 | |
parent | 9cb6d9e93baa6d4e0b8a650126a1fa3ef4c9810e (diff) | |
download | mobly-snippet-lib-08b72cb1ecc65b8ebb23c433dbe4fd45c8ac95d9.tar.gz |
Fix type conversion failure in some circumstances. (#135)
-rw-r--r-- | third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java index 214ffe7..1186399 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java @@ -23,7 +23,9 @@ import com.google.android.mobly.snippet.manager.SnippetManager; import com.google.android.mobly.snippet.manager.SnippetObjectConverterManager; import com.google.android.mobly.snippet.util.AndroidUtil; import java.lang.annotation.Annotation; +import java.lang.reflect.Array; import java.lang.reflect.Constructor; +import java.lang.reflect.GenericArrayType; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; @@ -105,6 +107,14 @@ public final class MethodDescriptor { private static Object convertParameter(final JSONArray parameters, int index, Type type) throws JSONException, RpcError { try { + // The refelection system sometimes returns a GenericArrayType type + // instead of a raw type, causing issues with later type + // comparisons. + if (type instanceof GenericArrayType) { + Type componentType = ((GenericArrayType) type).getGenericComponentType(); + type = Array.newInstance((Class<?>) componentType, 0).getClass(); + } + // We must handle null and numbers explicitly because we cannot magically cast them. We // also need to convert implicitly from numbers to bools. if (parameters.isNull(index)) { |