aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2023-02-13 13:06:32 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-02-13 13:06:32 +0000
commita0d573ecd4fff61f7d49c325486d96e935761e30 (patch)
tree967af8f9511a83034c784fcc5dcaab43a4e5eba5
parentcbf52fcd960a22a9d03b71ae828c26640e04457e (diff)
parentfddc768e9102cd7bee0aa6fe153a68e6e9fb204a (diff)
downloadlibnativehelper-a0d573ecd4fff61f7d49c325486d96e935761e30.tar.gz
Merge "Handle cases where exceptions may be thrown."
-rw-r--r--JNIHelp.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/JNIHelp.c b/JNIHelp.c
index fba7f8d..cb008a6 100644
--- a/JNIHelp.c
+++ b/JNIHelp.c
@@ -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;