ART: Fix call site resolution

Parameter type resolution should use the target method's DEX file.

Bug: 70166093
Test: art/test/run-test --host 714
Change-Id: Ic4961a905144ee85b36d02476506c4078c6cdf7a
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 32d3040..ae707f0 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8368,7 +8368,6 @@
 
 mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod(
     Thread* self,
-    const DexFile* const dex_file,
     const DexFile::MethodHandleItem& method_handle,
     ArtMethod* referrer) {
   DexFile::MethodHandleType handle_type =
@@ -8492,19 +8491,20 @@
     return nullptr;
   }
 
-  Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
-  Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
   int32_t index = 0;
-
   if (receiver_count != 0) {
     // Insert receiver
     method_params->Set(index++, target_method->GetDeclaringClass());
   }
-
-  DexFileParameterIterator it(*dex_file, target_method->GetPrototype());
+  DexFileParameterIterator it(*target_method->GetDexFile(), target_method->GetPrototype());
+  Handle<mirror::DexCache> target_method_dex_cache(hs.NewHandle(target_method->GetDexCache()));
+  Handle<mirror::ClassLoader> target_method_class_loader(hs.NewHandle(target_method->GetClassLoader()));
   while (it.HasNext()) {
+    DCHECK_LT(index, num_params);
     const dex::TypeIndex type_idx = it.GetTypeIdx();
-    ObjPtr<mirror::Class> klass = ResolveType(type_idx, dex_cache, class_loader);
+    ObjPtr<mirror::Class> klass = ResolveType(type_idx,
+                                              target_method_dex_cache,
+                                              target_method_class_loader);
     if (nullptr == klass) {
       DCHECK(self->IsExceptionPending());
       return nullptr;
@@ -8554,7 +8554,7 @@
     case DexFile::MethodHandleType::kInvokeConstructor:
     case DexFile::MethodHandleType::kInvokeDirect:
     case DexFile::MethodHandleType::kInvokeInterface:
-      return ResolveMethodHandleForMethod(self, dex_file, method_handle, referrer);
+      return ResolveMethodHandleForMethod(self, method_handle, referrer);
   }
 }
 
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 3e3425f..16fa1ce 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -979,7 +979,6 @@
       REQUIRES_SHARED(Locks::mutator_lock_);
 
   mirror::MethodHandle* ResolveMethodHandleForMethod(Thread* self,
-                                                     const DexFile* const dex_file,
                                                      const DexFile::MethodHandleItem& method_handle,
                                                      ArtMethod* referrer)
       REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index d53da21..12b8c38 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -1183,10 +1183,9 @@
   }
 
   Handle<mirror::Object> object(hs.NewHandle(result.GetL()));
-
-  // Check the result is not null.
   if (UNLIKELY(object.IsNull())) {
-    ThrowNullPointerException("CallSite == null");
+    // This will typically be for LambdaMetafactory which is not supported.
+    ThrowNullPointerException("Bootstrap method returned null");
     return nullptr;
   }
 
@@ -1202,7 +1201,7 @@
   // Check the call site target is not null as we're going to invoke it.
   Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
   if (UNLIKELY(target.IsNull())) {
-    ThrowNullPointerException("CallSite target == null");
+    ThrowNullPointerException("Target for call-site is null");
     return nullptr;
   }