diff options
Diffstat (limited to 'src/com/google/testing/littlemock/LittleMock.java')
-rw-r--r-- | src/com/google/testing/littlemock/LittleMock.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/com/google/testing/littlemock/LittleMock.java b/src/com/google/testing/littlemock/LittleMock.java index 140f853..0e96938 100644 --- a/src/com/google/testing/littlemock/LittleMock.java +++ b/src/com/google/testing/littlemock/LittleMock.java @@ -1314,6 +1314,17 @@ public class LittleMock { newInstance.setAccessible(true); return (T) newInstance.invoke(null, clazz, constructorId); } catch (Exception ignored) {} + // try dalvikvm, with change https://android-review.googlesource.com/#/c/52331/ + try { + Method getConstructorId = ObjectStreamClass.class + .getDeclaredMethod("getConstructorId", Class.class); + getConstructorId.setAccessible(true); + final long constructorId = (Long) getConstructorId.invoke(null, Object.class); + final Method newInstance = ObjectStreamClass.class + .getDeclaredMethod("newInstance", Class.class, long.class); + newInstance.setAccessible(true); + return (T) newInstance.invoke(null, clazz, constructorId); + } catch (Exception ignored) {} throw new IllegalStateException("unsafe create instance failed"); } |