Fix null dereference in SweepInterpreterCaches

There can be a race with ClearAllInterpreterCaches

Bug: 242495493
Test: test.py -b -r --host
Change-Id: Ic16dbfd54b6474498afd9c11e83aa7f5dc2f5e4c
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 5492cc8..2c465c9 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -4455,6 +4455,9 @@
 
 static void SweepCacheEntry(IsMarkedVisitor* visitor, const Instruction* inst, size_t* value)
     REQUIRES_SHARED(Locks::mutator_lock_) {
+  // WARNING: The interpreter will not modify the cache while this method is running in GC.
+  //          However, ClearAllInterpreterCaches can still run if any dex file is closed.
+  //          Therefore the cache entry can be nulled at any point through this method.
   if (inst == nullptr) {
     return;
   }
@@ -4480,6 +4483,9 @@
     case Opcode::CONST_STRING:
     case Opcode::CONST_STRING_JUMBO: {
       mirror::Object* object = reinterpret_cast<mirror::Object*>(*value);
+      if (object == nullptr) {
+        return;
+      }
       mirror::Object* new_object = visitor->IsMarked(object);
       // We know the string is marked because it's a strongly-interned string that
       // is always alive (see b/117621117 for trying to make those strings weak).