Don't re-use arttest when calling loadLibrary.
When Android's build environment variables are set with envsetup.sh,
the test "works" ok, by getting a LinkageError because two class loaders
try to load the same library. I guess that is the reason for the
if (ExceptionCheck()) after the loading.
However, if the environment variables are set manually, there are
cases where the paths provided between a Java loadLibrary, and a
native loadLibrary are different, so we end up loading the library twice.
This makes the assertion line 32 fail on the second JNI_OnLoad call.
In my particular environment, ANDROID_BUILD_TOP was something lie
/foo/bar/..//.
This change stops re-using the same library, and makes the expected
outcome constant: the native call of loadLibrary with a non exist
library must throw a LinkageError.
Change-Id: I8721a03715e099c55fb8b2b87813f1e772c8e83d
diff --git a/test/004-JniTest/jni_test.cc b/test/004-JniTest/jni_test.cc
index c2877be..544cbc5 100644
--- a/test/004-JniTest/jni_test.cc
+++ b/test/004-JniTest/jni_test.cc
@@ -294,20 +294,20 @@
assert(!env->ExceptionCheck());
// Create a string object.
- jobject library_string = env->NewStringUTF("arttest");
+ jobject library_string = env->NewStringUTF("non_existing_library");
assert(library_string != nullptr);
assert(!env->ExceptionCheck());
env->CallStaticVoidMethod(system_clazz, loadLibraryMethodId, library_string);
- if (env->ExceptionCheck()) {
- // At most we expect UnsatisfiedLinkError.
- jthrowable thrown = env->ExceptionOccurred();
- env->ExceptionClear();
+ assert(env->ExceptionCheck());
- jclass unsatisfied_link_error_clazz = env->FindClass("java/lang/UnsatisfiedLinkError");
- jclass thrown_class = env->GetObjectClass(thrown);
- assert(env->IsSameObject(unsatisfied_link_error_clazz, thrown_class));
- }
+ // We expect UnsatisfiedLinkError.
+ jthrowable thrown = env->ExceptionOccurred();
+ env->ExceptionClear();
+
+ jclass unsatisfied_link_error_clazz = env->FindClass("java/lang/UnsatisfiedLinkError");
+ jclass thrown_class = env->GetObjectClass(thrown);
+ assert(env->IsSameObject(unsatisfied_link_error_clazz, thrown_class));
}
}