Handle unresolved field type in compiler.

Make behavior consistent with interpreter, by only resolving field types
when the stored value is not null.

Note that this differs from RI behavior which throws a
NoClassDefFoundError when loading the BadField class.

Bug: 79751666

Test: 173-missing-field-type
Change-Id: I1e584f3129fd651bee1c9635c90bc30e13190a90
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index df236c1..cd68b2a 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -34,6 +34,7 @@
 #include "oat_file.h"
 #include "optimizing_compiler_stats.h"
 #include "quicken_info.h"
+#include "reflective_handle_scope-inl.h"
 #include "scoped_thread_state_change-inl.h"
 #include "sharpening.h"
 #include "ssa_builder.h"
@@ -1934,7 +1935,14 @@
     return nullptr;
   }
 
-  return resolved_field;
+  StackArtFieldHandleScope<1> rhs(soa.Self());
+  ReflectiveHandle<ArtField> resolved_field_handle(rhs.NewHandle(resolved_field));
+  if (resolved_field->ResolveType().IsNull()) {
+    // ArtField::ResolveType() may fail as evidenced with a dexing bug (b/78788577).
+    soa.Self()->ClearException();
+    return nullptr;  // Failure
+  }
+  return resolved_field_handle.Get();
 }
 
 void HInstructionBuilder::BuildStaticFieldAccess(const Instruction& instruction,