Handle the situation we could not load the class.

This happens with the JIT thread through custom class loaders.

Test: test.py
Bug: 73760543
Bug: 159595198
Change-Id: Ic27a9f8ddd02ba1408963d3cb00ef1ef4da3c063
Merged-In: Ic27a9f8ddd02ba1408963d3cb00ef1ef4da3c063
(cherry picked from commit 076141924de11466aad8dcd845630605fd1963e1)
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index f718089..c39c5be 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8788,6 +8788,13 @@
       // We normaly should not end up here. However the verifier currently doesn't guarantee
       // the invariant of having the klass in the class table. b/73760543
       klass = ResolveType(method_id.class_idx_, dex_cache, class_loader);
+      if (klass == nullptr) {
+        // This can only happen if the current thread is not allowed to load
+        // classes.
+        DCHECK(!Thread::Current()->CanLoadClasses());
+        DCHECK(Thread::Current()->IsExceptionPending());
+        return nullptr;
+      }
     }
   } else {
     // The method was not in the DexCache, resolve the declaring class.