Make the class loading behavior closer to the RI's.

Change-Id: Ic2ab91dc5a455a97dbcbe1f2d7b464a888d5bb66
diff --git a/src/class_linker.cc b/src/class_linker.cc
index e0bcd04..c14f6bd 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -1103,8 +1103,6 @@
     return EnsureResolved(klass);
   }
   // Class is not yet loaded.
-  JNIEnv* env = self->GetJniEnv();
-  ScopedLocalRef<jthrowable> cause(env, NULL);
   if (descriptor[0] == '[') {
     return CreateArrayClass(descriptor, class_loader);
 
@@ -1134,6 +1132,7 @@
   } else {
     std::string class_name_string(DescriptorToDot(descriptor));
     ScopedThreadStateChange(self, Thread::kNative);
+    JNIEnv* env = self->GetJniEnv();
     ScopedLocalRef<jclass> c(env, AddLocalReference<jclass>(env, GetClassRoot(kJavaLangClassLoader)));
     CHECK(c.get() != NULL);
     // TODO: cache method?
@@ -1146,16 +1145,9 @@
     ScopedLocalRef<jobject> class_loader_object(env, AddLocalReference<jobject>(env, class_loader));
     ScopedLocalRef<jobject> result(env, env->CallObjectMethod(class_loader_object.get(), mid,
                                                               class_name_object.get()));
-    cause.reset(env->ExceptionOccurred());
-    if (cause.get() != NULL) {
-      // Throw LinkageErrors unmolested...
-      env->ExceptionClear();
-      static jclass LinkageError_class = CacheClass(env, "java/lang/LinkageError");
-      if (env->IsInstanceOf(cause.get(), LinkageError_class)) {
-        env->Throw(cause.get());
-        return NULL;
-      }
-      // ...otherwise fall through and throw NCDFE.
+    if (env->ExceptionOccurred()) {
+      // If the ClassLoader threw, pass that exception up.
+      return NULL;
     } else if (result.get() == NULL) {
       // broken loader - throw NPE to be compatible with Dalvik
       ThrowNullPointerException("ClassLoader.loadClass returned null for %s",
@@ -1168,14 +1160,6 @@
   }
 
   ThrowNoClassDefFoundError("Class %s not found", PrintableString(StringPiece(descriptor)).c_str());
-  if (cause.get() != NULL) {
-    // Initialize the cause of the NCDFE.
-    ScopedLocalRef<jthrowable> ncdfe(env, env->ExceptionOccurred());
-    env->ExceptionClear();
-    static jmethodID initCause_mid = env->GetMethodID(env->FindClass("java/lang/Throwable"), "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
-    env->CallObjectMethod(ncdfe.get(), initCause_mid, cause.get());
-    env->Throw(ncdfe.get());
-  }
   return NULL;
 }