summaryrefslogtreecommitdiff
path: root/test/068-classloader/src/Main.java
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2016-04-13 01:19:08 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2016-04-13 01:19:09 +0000
commite4010c6a1e838432758007906cae6359c0f33c9d (patch)
treecf041cca8b170c7e0f51c517aa082a639aac2fd9 /test/068-classloader/src/Main.java
parente3ccf744a6f7e4946d1d813d45d5dab20f0759d3 (diff)
parent6d25cf6cbda1b95fb014a3fd22c01a6bdf47725e (diff)
Merge "Fix InsertDexFileInToClassLoader to handle null class loaders"
Diffstat (limited to 'test/068-classloader/src/Main.java')
-rw-r--r--test/068-classloader/src/Main.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/068-classloader/src/Main.java b/test/068-classloader/src/Main.java
index 361e2938e3..b2d843b351 100644
--- a/test/068-classloader/src/Main.java
+++ b/test/068-classloader/src/Main.java
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
/**
* Class loader test.
*/
@@ -62,6 +65,28 @@ public class Main {
testSeparation();
testClassForName();
+
+ testNullClassLoader();
+ }
+
+ static void testNullClassLoader() {
+ try {
+ /* this is the "alternate" DEX/Jar file */
+ String DEX_FILE = System.getenv("DEX_LOCATION") + "/068-classloader-ex.jar";
+ /* on Dalvik, this is a DexFile; otherwise, it's null */
+ Class mDexClass = Class.forName("dalvik.system.DexFile");
+ Constructor ctor = mDexClass.getConstructor(new Class[] {String.class});
+ Object mDexFile = ctor.newInstance(DEX_FILE);
+ Method meth = mDexClass.getMethod("loadClass",
+ new Class[] { String.class, ClassLoader.class });
+ Object klass = meth.invoke(mDexFile, "Mutator", null);
+ if (klass == null) {
+ throw new AssertionError("loadClass with nullclass loader failed");
+ }
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ System.out.println("Loaded class into null class loader");
}
static void testSeparation() {