summaryrefslogtreecommitdiff
path: root/bug-8297640.patch
blob: 24f2c69a063480c025e5102ff0019e118e729013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Index: src/com/google/testing/littlemock/LittleMock.java
===================================================================
--- src/com/google/testing/littlemock/LittleMock.java	(revision 19)
+++ src/com/google/testing/littlemock/LittleMock.java	(working copy)
@@ -1268,6 +1268,17 @@
       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");
   }