Revert "Fix correctness for fast path class loading"

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

Test: TH
This reverts commit ef04ac6c05fa344428008ffa1eac7316c64a3467.

(cherry picked from commit 2e2f9e8c6989dec22e4199a773a1e03954f82365)

Merged-In: I2ee8a20419da251eed2620b7feb390053c0cdcb9
Change-Id: I2ee8a20419da251eed2620b7feb390053c0cdcb9
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 5373435..c5aad58 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -1520,16 +1520,13 @@
   std::string temp;
   const char* descriptor = exception->GetClass()->GetDescriptor(&temp);
   const char* expected_exceptions[] = {
-      "Ljava/lang/ClassFormatError;",
-      "Ljava/lang/ClassCircularityError;",
       "Ljava/lang/IllegalAccessError;",
       "Ljava/lang/IncompatibleClassChangeError;",
       "Ljava/lang/InstantiationError;",
       "Ljava/lang/LinkageError;",
       "Ljava/lang/NoClassDefFoundError;",
       "Ljava/lang/NoSuchFieldError;",
-      "Ljava/lang/NoSuchMethodError;",
-      "Ljava/lang/VerifyError;",
+      "Ljava/lang/NoSuchMethodError;"
   };
   bool found = false;
   for (size_t i = 0; (found == false) && (i < arraysize(expected_exceptions)); ++i) {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 419e3f7..fa5cb92 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)));
     }
   }
 
diff --git a/runtime/class_loader_utils.h b/runtime/class_loader_utils.h
index 2e85043..b809baf 100644
--- a/runtime/class_loader_utils.h
+++ b/runtime/class_loader_utils.h
@@ -98,6 +98,7 @@
         }
       }
     }
+    self->AssertNoPendingException();
   }
   return defaultReturn;
 }
diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc
index 11e02a2..46162c1 100644
--- a/runtime/native/java_lang_VMClassLoader.cc
+++ b/runtime/native/java_lang_VMClassLoader.cc
@@ -57,12 +57,8 @@
       REQUIRES_SHARED(Locks::mutator_lock_) {
     ObjPtr<mirror::Class> result;
     if (cl->FindClassInBaseDexClassLoader(soa, self, descriptor, hash, class_loader, &result)) {
-      DCHECK(!self->IsExceptionPending());
       return result;
     }
-    if (self->IsExceptionPending()) {
-      self->ClearException();
-    }
     return nullptr;
   }
 };
diff --git a/test/803-no-super/expected.txt b/test/803-no-super/expected.txt
index c324e7b..5036991 100644
--- a/test/803-no-super/expected.txt
+++ b/test/803-no-super/expected.txt
@@ -1,2 +1,2 @@
-java.lang.NoClassDefFoundError: Failed resolution of: LNoClass;
+java.lang.ClassNotFoundException: NoSuper1
 Done!
diff --git a/test/803-no-super/src/Main.java b/test/803-no-super/src/Main.java
index 5551271..a07e042 100644
--- a/test/803-no-super/src/Main.java
+++ b/test/803-no-super/src/Main.java
@@ -21,7 +21,7 @@
     public static void main(String[] args) throws Exception {
         try {
             Class<?> c = Class.forName("NoSuper1");
-        } catch (Error e) {
+        } catch (Exception e) {
             System.out.println(e);
         }
         System.out.println("Done!");