Add null check to CheckVirtualMethod
There was a runtime SIGSEGV that should have been a check jni
failure.
Also added regression test.
Bug: 16320699
(cherry picked from commit 167350d9c781c5e3893714bb26ab5cb1c4abf6b4)
Change-Id: I7edea6af6517f1e5628678e824b8307daf491418
diff --git a/runtime/jni_internal_test.cc b/runtime/jni_internal_test.cc
index 844d14a..b236ede 100644
--- a/runtime/jni_internal_test.cc
+++ b/runtime/jni_internal_test.cc
@@ -746,6 +746,21 @@
GetMethodIdBadArgumentTest(true);
}
+TEST_F(JniInternalTest, CallVoidMethodNullReceiver) {
+ jclass jlobject = env_->FindClass("java/lang/Object");
+ jmethodID method;
+
+ // Check that GetMethodID for java.lang.NoSuchMethodError.<init>(String) finds the constructor.
+ method = env_->GetMethodID(jlobject, "<init>", "()V");
+ EXPECT_NE(nullptr, method);
+ EXPECT_FALSE(env_->ExceptionCheck());
+
+ // Null object to CallVoidMethod.
+ CheckJniAbortCatcher check_jni_abort_catcher;
+ env_->CallVoidMethod(nullptr, method);
+ check_jni_abort_catcher.Check("null");
+}
+
TEST_F(JniInternalTest, GetStaticMethodID) {
jclass jlobject = env_->FindClass("java/lang/Object");
jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");