diff --git a/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs b/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs index 2e31674b11a..e573fe3182a 100644 --- a/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs +++ b/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs @@ -45,7 +45,7 @@ public void RegisterTypeOnNewThread () { Java.Lang.JavaSystem.LoadLibrary ("reuse-threads"); int ret = rt_register_type_on_new_thread ("from.NewThread", Application.Context.ClassLoader.Handle); - Assert.AreEqual (0, ret, "Java type registration on a new thread failed"); + Assert.AreEqual (0, ret, $"Java type registration on a new thread failed with code {ret}"); } [Test] diff --git a/tests/Mono.Android-Tests/jni/reuse-threads.c b/tests/Mono.Android-Tests/jni/reuse-threads.c index c4d96083401..48a11a78add 100644 --- a/tests/Mono.Android-Tests/jni/reuse-threads.c +++ b/tests/Mono.Android-Tests/jni/reuse-threads.c @@ -232,32 +232,60 @@ _register_type_from_new_thread (void *data) int ret = 0; jclass ClassLoader_class = (*env)->FindClass (env, "java/lang/ClassLoader"); - jmethodID loadClass = (*env)->GetMethodID (env, ClassLoader_class, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); - jobject loaded_class = (*env)->CallObjectMethod (env, context->class_loader, loadClass, context->java_type_name); - jobject instance = NULL; + if (ClassLoader_class == NULL) { + ret = -102; + __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: unable to find the 'java/lang/ClassLoader' class!"); + goto cleanup; + } + + jmethodID loadClass = (*env)->GetMethodID (env, ClassLoader_class, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); + if (loadClass == NULL) { + ret = -103; + __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: unable to get id of method 'loadClass' in the 'java/lang/ClassLoader' class!"); + goto cleanup; + } + + jobject loaded_class = (*env)->CallObjectMethod (env, context->class_loader, loadClass, context->java_type_name); if ((*env)->ExceptionOccurred (env) != NULL) { (*env)->ExceptionClear (env); __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: class '%s' cannot be loaded, Java exception thrown!", context->java_type_name); (*env)->ExceptionDescribe (env); - ret = -102; + ret = -104; + goto cleanup; + } + + if (loaded_class == NULL) { + ret = -105; + __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: 'java/lang/ClassLoader' wasn't able to load the '%s' class!", context->java_type_name); goto cleanup; } jmethodID Object_ctor = (*env)->GetMethodID (env, loaded_class, "", "()V"); - instance = (*env)->NewObject (env, loaded_class, Object_ctor); + if (Object_ctor == NULL) { + ret = -106; + __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: unable to find the '%s' class constructor!", context->java_type_name); + goto cleanup; + } + + jobject instance = (*env)->NewObject (env, loaded_class, Object_ctor); if ((*env)->ExceptionOccurred (env) != NULL || instance == NULL) { (*env)->ExceptionClear (env); __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: instance of class '%s' wasn't created!", context->java_type_name); (*env)->ExceptionDescribe (env); - ret = -103; + ret = -107; + } + + if (instance == NULL) { + ret = -108; + __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "FAILURE: unable to create instance of the '%s' class!", context->java_type_name); } cleanup: (*env)->PopLocalFrame (env, NULL); - return 0; + return ret; } JNIEXPORT int JNICALL