Skip to content

Commit

Permalink
Fix potentially pending JNI exceptions.
Browse files Browse the repository at this point in the history
(cherry picked from commit 9440549)
  • Loading branch information
christianhaeubl authored and zakkak committed May 22, 2024
1 parent d35fcbb commit 49b4215
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <poll.h>
#include <netdb.h>
#include <errno.h>
#include <dlfcn.h>
Expand Down Expand Up @@ -311,10 +311,15 @@ JNIEXPORT jobject JNICALL JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject acti
return (*env)->CallObjectMethod(env, action, run);
}
}

/* Some error occurred - clear pending exception and try to report the error. */
(*env)->ExceptionClear(env);

jclass errorClass = (*env)->FindClass(env, "java/lang/InternalError");
if (errorClass != NULL && !(*env)->ExceptionCheck(env)) {
(*env)->ThrowNew(env, errorClass, "Could not invoke PrivilegedAction");
} else {
(*env)->ExceptionClear(env);
(*env)->FatalError(env, "PrivilegedAction could not be invoked and the error could not be reported");
}
return NULL;
Expand Down

0 comments on commit 49b4215

Please sign in to comment.