blob: 24f2c69a063480c025e5102ff0019e118e729013 [file] [log] [blame]
Ian Parkinson328b01e2013-03-01 18:33:50 +00001Index: src/com/google/testing/littlemock/LittleMock.java
2===================================================================
3--- src/com/google/testing/littlemock/LittleMock.java (revision 19)
4+++ src/com/google/testing/littlemock/LittleMock.java (working copy)
5@@ -1268,6 +1268,17 @@
6 newInstance.setAccessible(true);
7 return (T) newInstance.invoke(null, clazz, constructorId);
8 } catch (Exception ignored) {}
9+ // try dalvikvm, with change https://android-review.googlesource.com/#/c/52331/
10+ try {
11+ Method getConstructorId = ObjectStreamClass.class
12+ .getDeclaredMethod("getConstructorId", Class.class);
13+ getConstructorId.setAccessible(true);
14+ final long constructorId = (Long) getConstructorId.invoke(null, Object.class);
15+ final Method newInstance = ObjectStreamClass.class
16+ .getDeclaredMethod("newInstance", Class.class, long.class);
17+ newInstance.setAccessible(true);
18+ return (T) newInstance.invoke(null, clazz, constructorId);
19+ } catch (Exception ignored) {}
20 throw new IllegalStateException("unsafe create instance failed");
21 }
22