summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Parkinson <ianp@google.com>2013-03-01 18:33:50 +0000
committerIan Parkinson <ianp@google.com>2013-03-01 18:34:16 +0000
commit328b01eada8965cd38feea884d4080c31e3763b0 (patch)
treed3491fe1a58a8a19a670bd5727c9681bda8a62e9
parent500720cc631d69537831b9d01ad09dd064c97f7a (diff)
downloadlittlemock-328b01eada8965cd38feea884d4080c31e3763b0.tar.gz
Bug: 8297640 Change-Id: I0a18ec915ec69170e8a4cfc80a211fd07be9df00
-rw-r--r--README3
-rw-r--r--bug-8297640.patch22
-rw-r--r--src/com/google/testing/littlemock/LittleMock.java11
3 files changed, 35 insertions, 1 deletions
diff --git a/README b/README
index 86b8be6..847dac9 100644
--- a/README
+++ b/README
@@ -14,4 +14,5 @@ Can mock concrete classes, requires dexmaker.jar on classpath.
Local Modifications:
- Change to AppDataDirGuesser to handle the new class loader toString
format introduced in JB.
-
+- bug8297640.patch: update instantiation code to handle change in internal
+ methods
diff --git a/bug-8297640.patch b/bug-8297640.patch
new file mode 100644
index 0000000..24f2c69
--- /dev/null
+++ b/bug-8297640.patch
@@ -0,0 +1,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");
+ }
+
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");
}