Revert "Fix correctness for fast path class loading"

Bug: 130310316
Bug: 130293184
Bug: 130209120
Bug: 130680590

Test: TH
This reverts commit ef04ac6c05fa344428008ffa1eac7316c64a3467.

Change-Id: I2ee8a20419da251eed2620b7feb390053c0cdcb9
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 3f0713f..98c1b05 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2744,7 +2744,7 @@
 
     // Search the current class loader classpath.
     *result = FindClassInBaseDexClassLoaderClassPath(soa, descriptor, hash, class_loader);
-    return !soa.Self()->IsExceptionPending();
+    return true;
   }
 
   if (IsDelegateLastClassLoader(soa, class_loader)) {
@@ -2757,11 +2757,6 @@
     if (*result != nullptr) {
       return true;  // The class is part of the boot class path.
     }
-    if (self->IsExceptionPending()) {
-      // Pending exception means there was an error other than ClassNotFound that must be returned
-      // to the caller.
-      return false;
-    }
 
     if (!FindClassInSharedLibraries(soa, self, descriptor, hash, class_loader, result)) {
       return false;  // One of the shared library loader is not supported.
@@ -2774,11 +2769,6 @@
     if (*result != nullptr) {
       return true;  // Found the class in the current class loader
     }
-    if (self->IsExceptionPending()) {
-      // Pending exception means there was an error other than ClassNotFound that must be returned
-      // to the caller.
-      return false;
-    }
 
     // Handles as RegisterDexFile may allocate dex caches (and cause thread suspension).
     StackHandleScope<1> hs(self);
@@ -2812,6 +2802,7 @@
     }
     if (result == nullptr) {
       CHECK(self->IsExceptionPending()) << descriptor;
+      self->ClearException();
     }
   }
   return result;
@@ -2839,9 +2830,8 @@
                                                 *dex_class_def);
       if (klass == nullptr) {
         CHECK(soa.Self()->IsExceptionPending()) << descriptor;
+        soa.Self()->ClearException();
         // TODO: Is it really right to break here, and not check the other dex files?
-      } else {
-        DCHECK(!soa.Self()->IsExceptionPending());
       }
       ret = klass;
       return false;  // Found a Class (or error == nullptr), stop visit.
@@ -2910,10 +2900,8 @@
       DCHECK(known_hierarchy);
       DCHECK(result_ptr->DescriptorEquals(descriptor));
       descriptor_equals = true;
-    } else if (!self->IsExceptionPending()) {
+    } else {
       // Either the chain wasn't understood or the class wasn't found.
-      // If there is a pending exception we didn't clear, it is a not a ClassNotFoundException and
-      // we should return it instead of silently clearing and retrying.
       //
       // If the chain was understood but we did not find the class, let the Java-side
       // rediscover all this and throw the exception with the right stack trace. Note that
@@ -2944,9 +2932,9 @@
         ThrowNoClassDefFoundError("Invalid descriptor: %s.", descriptor);
         return nullptr;
       }
-
       std::string class_name_string(descriptor + 1, descriptor_length - 2);
       std::replace(class_name_string.begin(), class_name_string.end(), '/', '.');
+
       ScopedLocalRef<jobject> class_loader_object(
           soa.Env(), soa.AddLocalReference<jobject>(class_loader.Get()));
       ScopedLocalRef<jobject> result(soa.Env(), nullptr);
@@ -2972,9 +2960,6 @@
       result_ptr = soa.Decode<mirror::Class>(result.get());
       // Check the name of the returned class.
       descriptor_equals = (result_ptr != nullptr) && result_ptr->DescriptorEquals(descriptor);
-    } else {
-      DCHECK(!self->GetException()->InstanceOf(
-          GetClassRoot(ClassRoot::kJavaLangClassNotFoundException, this)));
     }
   }