Clear exception before calling ValidateSuperClassDescriptors

Since ValidateSuperClassDescriptors may also cause an exception, we
can't have any stale exceptions from EnsureInitialized otherwise there
may be aborts

TODO: Figure out how to add a test.

Bug: 131855081
Bug: 132690194
Test: test-art-host
Change-Id: Ia56af1ff497d30539a42a772979320df699b658a
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 540b8a6..78f5dc5 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -2154,6 +2154,9 @@
             InitializeDependencies(klass, class_loader, soa.Self());
         if (!is_app_image || (is_app_image && is_superclass_initialized)) {
           manager_->GetClassLinker()->EnsureInitialized(soa.Self(), klass, false, true);
+          // It's OK to clear the exception here since the compiler is supposed to be fault
+          // tolerant and will silently not initialize classes that have exceptions.
+          soa.Self()->ClearException();
         }
         // Otherwise it's in app image but superclasses can't be initialized, no need to proceed.
         old_status = klass->GetStatus();
@@ -2198,6 +2201,7 @@
             Runtime* const runtime = Runtime::Current();
             // Run the class initializer in transaction mode.
             runtime->EnterTransactionMode(is_app_image, klass.Get());
+
             bool success = manager_->GetClassLinker()->EnsureInitialized(soa.Self(), klass, true,
                                                                          true);
             // TODO we detach transaction from runtime to indicate we quit the transactional
@@ -2245,6 +2249,11 @@
             }
           }
         }
+        // Clear exception in case EnsureInitialized has caused one in the code above.
+        // It's OK to clear the exception here since the compiler is supposed to be fault
+        // tolerant and will silently not initialize classes that have exceptions.
+        soa.Self()->ClearException();
+
         // If the class still isn't initialized, at least try some checks that initialization
         // would do so they can be skipped at runtime.
         if (!klass->IsInitialized() &&