Make sure we rethrow the same exception we started with.
Bug: 6312938
Change-Id: I41d8adf27fd32103c55d9eeafa28a25c37f5029d
diff --git a/JNIHelp.cpp b/JNIHelp.cpp
index 7c0b146..bf50930 100644
--- a/JNIHelp.cpp
+++ b/JNIHelp.cpp
@@ -257,15 +257,16 @@
void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception) {
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
- scoped_local_ref<jthrowable> currentException(env);
+ scoped_local_ref<jthrowable> currentException(env, (*env)->ExceptionOccurred(e));
if (exception == NULL) {
- exception = (*env)->ExceptionOccurred(e);
+ exception = currentException.get();
if (exception == NULL) {
return;
}
+ }
+ if (currentException.get() != NULL) {
(*env)->ExceptionClear(e);
- currentException.reset(exception);
}
char* buffer = getStackTrace(env, exception);
@@ -278,7 +279,7 @@
free(buffer);
if (currentException.get() != NULL) {
- (*env)->Throw(e, exception); // rethrow
+ (*env)->Throw(e, currentException.get()); // rethrow
}
}