diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2017-04-18 03:52:39 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2017-04-18 19:39:40 +0800 |
commit | 7ccd9db9aae8fb16fbd157e7ad9a7882d5d51bdc (patch) | |
tree | 224486c6273ac3d7912b476a539628f61ac416c7 /platform/java | |
parent | b2a2b561e1795df5402b87f50e856e4b9a5d77b0 (diff) | |
download | mupdf-7ccd9db9aae8fb16fbd157e7ad9a7882d5d51bdc.tar.xz |
jni: Clear java exception when rethrow via fz_throw().
Previously when a java exception was pending CallObjectMethod()
was called. This is not permitted and so the exception must be
cleared before this function is called.
Secondly if the method called by CallObjectMethod() throws an
exception this exception was left pending when fz_throw() for
unknown java errors was called. Later on jni_rethrow() would
be called which in turn called ThrowNew(). This is not
permitted either, so the pending exception must be cleared
if caused by the call to CallObjectMethod().
Because fz_throw_java() always ends with a fz_throw() it is
safe to assume that the pre-existing exception (or the one
caused by CallObjectMethod()) will always be converted into
a fz_throw(), which in turn will be converted back to a java
exception since all calls to fz_throw_java() are enclosed in
fz_try() where fz_catch() ends with calling jni_rethrow().
Diffstat (limited to 'platform/java')
-rw-r--r-- | platform/java/mupdf_native.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index b2ec3eb1..3f211d78 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -251,8 +251,11 @@ static void fz_throw_java(fz_context *ctx, JNIEnv *env) jthrowable ex = (*env)->ExceptionOccurred(env); if (ex) { + (*env)->ExceptionClear(env); jobject msg = (*env)->CallObjectMethod(env, ex, mid_Object_toString); - if (!(*env)->ExceptionCheck(env) && msg) + if ((*env)->ExceptionCheck(env)) + (*env)->ExceptionClear(env); + else if (msg) { const char *p = (*env)->GetStringUTFChars(env, msg, NULL); if (p) |