You can't call initCause on a ClassNotFoundException.
Unlike NoClassDefFoundError, ClassNotFoundException has to be constructed
with a cause, or it will stupidly set a null cause which can't then be
changed.
This patch also fixes incorrect caching of jclass local references in statics,
which I noticed while fixing the test I'd broken.
Change-Id: I017f4a4e4158554427ccb37b650c985add28980c
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 3b5ac5d..8a2cc5c 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -1156,8 +1156,7 @@
// Initialize the cause of the NCDFE.
ScopedLocalRef<jthrowable> ncdfe(env, env->ExceptionOccurred());
env->ExceptionClear();
- static jclass Throwable_class = env->FindClass("java/lang/Throwable");
- static jmethodID initCause_mid = env->GetMethodID(Throwable_class, "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
+ static jmethodID initCause_mid = env->GetMethodID(env->FindClass("java/lang/Throwable"), "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
env->CallObjectMethod(ncdfe.get(), initCause_mid, cause.get());
env->Throw(ncdfe.get());
}