This release fixes several issues found shortly after releasing 0.22.0 which unfortunately required a few breaking changes.
Instead of bumping to 0.23 though, the assumption 🤞 is that no one will yet be depending on the recently-released
0.22.0 and so we can yank that and have this represent the first 0.22.x release.
In particular this addresses the following issues:
- Don't allow JNI calls with pending exceptions (undefined behaviour) #731
- JavaVM::attach_current_thread* should catch + clear exceptions #732
- Env::throw* APIs should return Err(Error::JavaException) #737
Added
Env::exception_catchprovides a convenient way of catching pending Java exceptions and mapping them toError::CaughtJavaException(#736)AttachGuard::detach_with_catchlets you explicitly detach/drop a guard (like::detach()) and catch any pending Java exception as aError::CaughtJavaException(#736).JClass::get_namelets you query the binary name for a class, such asjava.lang.String(#736)
Changed
The following APIs have had to be made fallible again, in order to safely check for pending exceptions before calling
JNI functions that are not documented as being safe to call with a pending exception:
Env::get_java_vm(GetJavaVMis not exception safe)Env::version(GetVersionis not exception safe)Env::is_same_object(IsSameObjectis not exception safe)Weak::is_garbage_collected(based onEnv::is_same_object)Weak::is_same_object(deprecated) and (based on
Env::is_same_object)Weak::is_weak_ref_to_same_object (deprecated)(based on
Env::is_same_object)
Note: These are a breaking change.
Fixed in #733
JavaVM::attach_current_thread*APIs all finish by callingAttachGuard::detach_with_catchto clear pending Java exceptions - mapping toError::CaughtJavaException(#736)Env::throw*APIs now returnError::JavaExceptionafter throwing and creating a pending exception that must be handled before using JNI further (#738)