diff options
author | 2015-04-22 03:48:14 +0000 | |
---|---|---|
committer | 2015-04-22 03:48:14 +0000 | |
commit | c2725c2c950b9372cd61d00accfc3c6bdab9e21c (patch) | |
tree | f33f3c24d65dc128d709fd89abe4bcf6f919e463 | |
parent | 08faf72e16a3b73b205e9f1ca618470b78174d4e (diff) | |
parent | 598854726a5d50c18fa720af6b097279e5e01584 (diff) |
Merge "Class.forName(..., ..., null) fixes - Add test for Class.forName(..., ..., null) - Simplify VMStack.getClosestUserClassLoader based on new behavior of Class.forName(..., ..., null)"
-rw-r--r-- | runtime/native/dalvik_system_VMStack.cc | 21 | ||||
-rw-r--r-- | test/068-classloader/expected.txt | 2 | ||||
-rw-r--r-- | test/068-classloader/src/Main.java | 13 |
3 files changed, 21 insertions, 15 deletions
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc index 2cdc68f5b2..17fbc4f85d 100644 --- a/runtime/native/dalvik_system_VMStack.cc +++ b/runtime/native/dalvik_system_VMStack.cc @@ -81,33 +81,26 @@ static jobject VMStack_getCallingClassLoader(JNIEnv* env, jclass) { return soa.AddLocalReference<jobject>(visitor.caller->GetDeclaringClass()->GetClassLoader()); } -static jobject VMStack_getClosestUserClassLoader(JNIEnv* env, jclass, jobject javaBootstrap, - jobject javaSystem) { +static jobject VMStack_getClosestUserClassLoader(JNIEnv* env, jclass) { struct ClosestUserClassLoaderVisitor : public StackVisitor { - ClosestUserClassLoaderVisitor(Thread* thread, mirror::Object* bootstrap_in, - mirror::Object* system_in) - : StackVisitor(thread, NULL), bootstrap(bootstrap_in), system(system_in), - class_loader(NULL) {} + explicit ClosestUserClassLoaderVisitor(Thread* thread) + : StackVisitor(thread, nullptr), class_loader(nullptr) {} bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK(class_loader == NULL); + DCHECK(class_loader == nullptr); mirror::Class* c = GetMethod()->GetDeclaringClass(); mirror::Object* cl = c->GetClassLoader(); - if (cl != NULL && cl != bootstrap && cl != system) { + if (cl != nullptr) { class_loader = cl; return false; } return true; } - mirror::Object* bootstrap; - mirror::Object* system; mirror::Object* class_loader; }; ScopedFastNativeObjectAccess soa(env); - mirror::Object* bootstrap = soa.Decode<mirror::Object*>(javaBootstrap); - mirror::Object* system = soa.Decode<mirror::Object*>(javaSystem); - ClosestUserClassLoaderVisitor visitor(soa.Self(), bootstrap, system); + ClosestUserClassLoaderVisitor visitor(soa.Self()); visitor.WalkStack(); return soa.AddLocalReference<jobject>(visitor.class_loader); } @@ -136,7 +129,7 @@ static jobjectArray VMStack_getThreadStackTrace(JNIEnv* env, jclass, jobject jav static JNINativeMethod gMethods[] = { NATIVE_METHOD(VMStack, fillStackTraceElements, "!(Ljava/lang/Thread;[Ljava/lang/StackTraceElement;)I"), NATIVE_METHOD(VMStack, getCallingClassLoader, "!()Ljava/lang/ClassLoader;"), - NATIVE_METHOD(VMStack, getClosestUserClassLoader, "!(Ljava/lang/ClassLoader;Ljava/lang/ClassLoader;)Ljava/lang/ClassLoader;"), + NATIVE_METHOD(VMStack, getClosestUserClassLoader, "!()Ljava/lang/ClassLoader;"), NATIVE_METHOD(VMStack, getStackClass2, "!()Ljava/lang/Class;"), NATIVE_METHOD(VMStack, getThreadStackTrace, "!(Ljava/lang/Thread;)[Ljava/lang/StackTraceElement;"), }; diff --git a/test/068-classloader/expected.txt b/test/068-classloader/expected.txt index bf131eee63..8725799fe1 100644 --- a/test/068-classloader/expected.txt +++ b/test/068-classloader/expected.txt @@ -11,3 +11,5 @@ Ctor: doubled implement, type 1 DoubledImplement one Got LinkageError on DI (early) Got LinkageError on IDI (early) +class Main +Got expected ClassNotFoundException diff --git a/test/068-classloader/src/Main.java b/test/068-classloader/src/Main.java index 1b2a4a4ceb..361e2938e3 100644 --- a/test/068-classloader/src/Main.java +++ b/test/068-classloader/src/Main.java @@ -21,7 +21,7 @@ public class Main { /** * Main entry point. */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { FancyLoader loader; loader = new FancyLoader(ClassLoader.getSystemClassLoader()); @@ -60,6 +60,8 @@ public class Main { testIfaceImplement(loader); testSeparation(); + + testClassForName(); } static void testSeparation() { @@ -479,4 +481,13 @@ public class Main { DoubledImplement2 di2 = ifaceSuper.getDoubledInstance2(); di2.one(); } + + static void testClassForName() throws Exception { + System.out.println(Class.forName("Main").toString()); + try { + System.out.println(Class.forName("Main", false, null).toString()); + } catch (ClassNotFoundException expected) { + System.out.println("Got expected ClassNotFoundException"); + } + } } |