Skip to content

Commit

Permalink
Fix potentially pending JNI exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Dec 4, 2023
1 parent af68df3 commit 9440549
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 9440549

Please sign in to comment.