The documentation
here gives a list of JNI functions that you're allowed to call when a JNI exception is pending. This list includes
PushLocalFrame(). It seems therefore that this code:
// Generate a 'class not found' exception.
environment->FindClass("foo");
// Generate an exception due to invalid capacity.
environment->PushLocalFrame(1000000000);
Should be safe. However, using the Android Studio emulator, on API level 27 and later, the PushLocalFrame() call crashes with a message like the following:
Abort message: 'Throwing new exception 'PushLocalFrame: Requested size exceeds maximum: 1000000006' with unexpected pending exception: java.lang.ClassNotFoundException: Didn't find class "foo" on path... [etc.]
Obviously PushLocalFrame() is unlikely to throw under normal circumstances, but crashing in this case seems to conflict with the documentation's claim that these functions are safe to call when there's an exception pending.
What behavior should be expected here? Could this be a flaw in the specification or documentation? Or perhaps a bug in the Android implementation?