From 51bb1c02c30b62e416c86b2f6985fe7ea3279603 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 10 Apr 2012 20:34:39 -0700 Subject: [PATCH] Make sure we rethrow the same exception we started with. Bug: 6312938 Change-Id: I41d8adf27fd32103c55d9eeafa28a25c37f5029d --- libnativehelper/JNIHelp.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libnativehelper/JNIHelp.cpp b/libnativehelper/JNIHelp.cpp index 7c0b146d9..bf50930c3 100644 --- a/libnativehelper/JNIHelp.cpp +++ b/libnativehelper/JNIHelp.cpp @@ -257,15 +257,16 @@ int jniThrowIOException(C_JNIEnv* env, int errnum) { void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception) { JNIEnv* e = reinterpret_cast(env); - scoped_local_ref currentException(env); + scoped_local_ref 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 @@ void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable ex free(buffer); if (currentException.get() != NULL) { - (*env)->Throw(e, exception); // rethrow + (*env)->Throw(e, currentException.get()); // rethrow } } -- 2.11.0