diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2023-02-13 13:06:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-02-13 13:06:32 +0000 |
commit | a0d573ecd4fff61f7d49c325486d96e935761e30 (patch) | |
tree | 967af8f9511a83034c784fcc5dcaab43a4e5eba5 | |
parent | cbf52fcd960a22a9d03b71ae828c26640e04457e (diff) | |
parent | fddc768e9102cd7bee0aa6fe153a68e6e9fb204a (diff) | |
download | libnativehelper-a0d573ecd4fff61f7d49c325486d96e935761e30.tar.gz |
Merge "Handle cases where exceptions may be thrown."
-rw-r--r-- | JNIHelp.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -100,14 +100,16 @@ static bool GetExceptionSummary(JNIEnv* env, jthrowable thrown, struct Expandabl (*env)->DeleteLocalRef(env, className); className = NULL; + bool success = false; jmethodID getMessage = FindMethod(env, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); jstring message = (jstring) (*env)->CallObjectMethod(env, thrown, getMessage); - if (message == NULL) { - return true; + if (message != NULL) { + success = (ExpandableStringAppend(dst, ": ") && AppendJString(env, message, dst)); + } else if ((*env)->ExceptionOccurred(env) == NULL) { + success = true; } - bool success = (ExpandableStringAppend(dst, ": ") && AppendJString(env, message, dst)); if (!success) { // Two potential reasons for reaching here: // @@ -169,7 +171,7 @@ static bool GetStackTrace(JNIEnv* env, jthrowable thrown, struct ExpandableStrin FindMethod(env, "java/lang/Throwable", "printStackTrace", "(Ljava/io/PrintWriter;)V"); (*env)->CallVoidMethod(env, thrown, printStackTrace, pw); - jstring trace = StringWriterToString(env, sw); + jstring trace = ((*env)->ExceptionOccurred(env) != NULL) ? NULL : StringWriterToString(env, sw); (*env)->DeleteLocalRef(env, pw); pw = NULL; |