Update Rust crate jni to 0.22 #235

Open
Renovate wants to merge 1 commit from renovate/jni-0.x into main
Owner

This PR contains the following updates:

Package Type Update Change
jni dependencies minor 0.21 -> 0.22

Release Notes

jni-rs/jni-rs (jni)

v0.22.0

Compare Source

Added
JavaVM / Thread Attachment APIs
  • JavaVM::singleton() lets you acquire the JavaVM for the process when you know that the JavaVM singleton has been initialized (#​595)
  • JavaVM::is_thread_attached can query whether the current thread is attached to the Java VM (#​570)
  • AttachGuard::from_unowned added as a low-level (unsafe) way to represent a thread attachment with a raw jni_sys::Env pointer (#​570)
  • AttachConfig exposes fine-grained control over thread attachment including Thread name, ThreadGroup and whether scoped or permanent. (#​606)
  • JavaVM::attach_current_thread_guard is a low-level (unsafe) building block for attaching threads that exposes the AttachGuard and AttachConfig control. (#​606)
  • JavaVM::attach_current_thread_with_config is a safe building block for attaching threads that hides the AttachGuard but exposes AttachConfig control. (#​606)
  • JavaVM::with_local_frame added as method to borrow a Env that is already attached to the current thread, after pushing a new JNI stack frame (#​570, #​673)
  • JavaVM::with_top_local_frame_frame added to borrow a Env for the top JNI stack frame (i.e. without pushing a new JNI stack frame) (#​570, #​673)
Reference Type APIs
  • A Reference trait for all reference types like JObject, JClass, JString, enabling Global and Weak to be generic over Reference and enabling safe casting and global caching of JClass references. (#​596)
  • Reference::lookup_class exposes a cached Global<JClass> for all Reference implementations (#​612)
  • LoaderContext + LoaderContext::load_class for loading classes, depending on available context (#​612)
  • Env::new_cast_global_ref acts like new_global_ref with a type cast (#​612)
  • Env::cast_global takes an owned Global<From> and returns an owned Global<To> (#​612)
  • Env::new_cast_local_ref acts like new_local_ref with a type cast (#​612)
  • Env::cast_local takes an owned local reference and returns a new type-cast wrapper (owned) (#​612)
  • Env::as_cast or Cast::new borrows any From: Reference (global or local) reference and returns a Cast<To> that will Deref into &To (#​612)
  • Env::as_cast_unchecked returns a Cast<To> like as_cast() but without a runtime IsInstanceOf check (#​669)
  • Env::as_cast_raw or Cast::from_raw borrows a raw jobject reference and returns a Cast<To> that will Deref into &To
  • Cast::new_unchecked and Cast::from_raw_unchecked let you borrow a reference with an (unsafe) type cast, with no runtime check
  • ::cast_local() methods as a convenience for all reference types, such as let s = JString::cast_local(obj)
  • const null() methods for all reference types.
  • Global::null() and Weak::null() construct null references (equivalent to Default::default()). (#​596)
JNI Environment APIs
  • Env::call_nonvirtual_method and Env::call_nonvirtual_method_unchecked to call non-virtual method. (#​454)
  • Env::to_reflected_method and Env::to_reflected_static_method for retrieving the Java reflection API instance for a method or constructor. (#​579)
  • Env::throw_new_void provides an easy way to throw an exception that's constructed with no message argument
  • Env::new_object_type_array<E> lets you you instantiate a JObjectArray with a given element type like new_object_type_array::<JString>
  • Env::load_class supports class lookups via the current Thread context class loader, with FindClass fallback. (#​674)
  • MethodSignature and FieldSignature types have been added for compile-time parsed JNI method and field signatures
Native Method APIs
  • EnvUnowned is an FFI-safe type that can be used to capture a jni_sys::Env pointer given to native methods and give it a named lifetime (this can then be temporarily upgraded to a &mut Env reference via EnvUnowned::with_env) (#​570)
  • Outcome is like a Result with the addition of a third Panic() variant, used for careful handling of errors in native methods. (#​664)
  • EnvOutcome represents an EnvUnowned::with_env outcome whose errors can be handle, with access to JNI, via an ErrorPolicy. (#​664)
  • ErrorPolicy is a trait with on_error and on_panic methods that can log native method errors or throw them as exceptions. (#​664)
  • ThrowRuntimeExAndDefault is an ErrorPolicy that throws any error as a RuntimeException (and returns a default value). (#​664)
  • LogErrorAndDefault is an ErrorPolicy that logs errors and returns a default value. (#​664)
  • LogContextErrorAndDefault is an ErrorPolicy that logs errors, with a given context string, and returns a default value. (#​664)
String APIs
  • New functions for converting Rust char to and from Java char and int (#​427 / #​434)

  • JavaStr/MUTF8Chars, JNIStr, and JNIString have several new methods and traits, most notably a to_str method that converts to a regular Rust string. (#​510 / #​512)

  • JNIStr now implements Debug, PartialEq, Eq, PartialOrd, Ord and Hash (#​615)

  • JNIString now implements Debug, PartialEq, Eq, PartialOrd, Ord, Hash and Clone (#​615)

  • PartialEq<&JNIStr> for JNIString allows JNIStr and JNIString to be compared. (#​615)

  • From<&JNIStr> and From<MUTF8Chars> implementations for JNIString. (#​615)

  • JNIStr::from_cstr safely does a zero-copy cast of a CStr to a JNIStr after a const modified-utf8 encoding validation (#​615,#​617, #​715)

  • JNIStr::to_bytes gives access to a &[u8] slice over the bytes of a JNI string (like CStr::to_bytes) (#​615)

java.lang APIs
  • JClassLoader as a Reference wrapper for java.lang.ClassLoader references (#​612)
  • JCollection, JSet and JIterator reference wrappers for java.util.Collection, java.util.Set and java.util.Iterator interfaces. (#​621)
  • JList::remove_item for removing a given value, by-reference, from the list (instead of by index). (#​713)
  • JList::clear allows a list to be cleared. (#​713)
  • JList::is_empty checks if a list is empty. (#​713)
  • JList::as_collection casts a list into a JCollection (#​713)
  • JObjectArray::new lets you construct a JObjectArray<E> with strong element type parameterization, instead of Env::new_object_array (#​657 + #​688)
  • JObjectArray::get/set_element let you get and set array elements as methods on the array. (#​654)
  • JPrimitiveArray::new lets you construct a JPrimitiveArray<E>, consistent with JObjectArray::new (#​688)
  • JStackTraceElement gives access to stack frame info within a stack trace, like filename, line number etc (#​657)
  • JString now has ::new(), ::from_str and ::from_jni_str constructor methods (#​960)
  • JThread as a Reference wrapper for java.lang.Thread references (#​612)
  • JThrowable::get_message is a binding for getMessage() and gives easy access to an exception message
  • JThrowable::get_stack_trace is a binding for getStackTrace(), returning a JObjectArray<JStackTraceElement>
Macros
  • The #[jni_mangle()] attribute proc macro can export an extern "system" native method with a mangled name like "Java_com_example_myMethod" so it can be automatically resolved within a shared library by the JVM (#​693)
  • The jni_str! and jni_cstr! macros can encode a MUTF-8 &'static JNIStr or &' static CStr at compile time with full unicode support. (#​696)
  • The jni_sig!, jni_sig_str!, jni_sig_cstr! and jni_sig_jstr! macros can parse and compile signatures like (arg0: jint, arg1: JString) -> JString into MethodSignature and FieldSignature descriptors or JNI string literals like "(ILjava/lang/String;)Ljava/lang/String;" (#​697)
  • The native_method! macro binds a single native method to a Rust function with type safety and optionally exports it too. (#​698)
  • The bind_java_type! macro can generate full Rust bindings for Java types (classes and interfaces) with fields, constructors, methods and native methods (#​712)
Changed
JavaVM / Thread Attachment APIs
  • JNI version requirements are more explicit in the API and the crate now requires at least JNI >= 1.4. It needs >= 1.2 so it can check for exceptions and needs >= 1.4 to avoid runtime checks for direct byte buffers (#​478)
  • At a low-level (unsafe), all thread attachments (not just scoped attachments) are now represented by an owned or unowned AttachGuard
  • AttachGuard usage is now considered unsafe since the type must be pinned to the stack (but that can't be guaranteed by the Rust type system alone).
  • To allow safe thread attachments (that ensure their AttachGuard is pinned to the stack), attachment APIs take a FnOnce whose &mut Env arg borrows from a hidden AttachGuard
    • JavaVM::attach_current_thread requests a permanent thread attachment (reducing cost of future attach_current_thread() calls)
    • JavaVM::attach_current_thread_for_scope requests a thread attachment that's detached after the given closure returns.
  • JavaVM::get_java_vm_pointer has been renamed JavaVM::get_raw for consistency.
  • JavaVM::new and JavaVM::with_libjvm now prevent libjvm from being unloaded. This isn't necessary for HotSpot, but other JVMs could crash if we don't do this. (#​554)
Reference and Primitive Types
  • Make from_raw(), into_raw() and null() methods const fn. (#​453)

  • Make from_raw() require an Env reference so the returned wrapper is guaranteed to have a local reference frame lifetime (#​670)

  • GlobalRef and WeakRef have been renamed to Global and Weak and are now generic, parameterized, transparent wrappers over 'static reference types like Global<JClass<'static>> (no longer an Arc holding a reference and VM pointer) (#​596)

    • Global and Weak no longer implement Clone, since JNI is required to create new reference (you'll need to explicitly use env.new_global_ref)
    • Global and Weak both implement Default, which will represent ::null() references (equivalent to JObject::null())
  • Global::into_raw replaces Global::try_into_raw and is infallible (#​596)

  • AutoLocal has been renamed to Auto with a deprecated type alias for AutoLocal to sign post the rename.

  • AutoElements was simplified to only be parameterized by one lifetime for the array reference, and accepts any AsRef<JPrimitiveArray<T>> as a reference. (#​508)

  • JObjectArray supports generic element types like JObjectArray<JString>

  • JavaType was simplified to not capture object names or array details (like ReturnType) since these details don't affect JValue type checks and had a hidden cost that was redundant.

  • JValueGen has been removed. JValue and JValueOwned are now separate, unrelated, non-generic types.
    (#​429) (Note: previously JValue and JValueOwned were type aliases for
    JValueGen, which was an internal type, but this design led to confusing error messages that made them harder to use)

JNI Environment APIs
  • JNIEnv is no longer a #[transparent] FFI-safe pointer wrapper and has been split into EnvUnowned (for FFI/native method args) and Env (non-FFI) (#​634)

  • A JNIEnv type alias shows a verbose deprecation warning that explains how to migrate from JNIEnv to EnvUnowned and Env (#​634)

  • Env::get_version has been renamed to Env::version (#​478)

  • Env is no longer ever exposed in the API by-value can only be accessed by borrowing from a thread attachment AttachGuard.

  • Env implements runtime borrow checking to ensure new local references may only be associated with the top JNI stack frame

  • JavaVM::get_env is replaced by JavaVM::get_env_attachment which returns an AttachGuard if the current thread is attached. (#​570)

  • The following functions are now infallible (#​478):

    • Env::version
    • Env::get_java_vm
    • Env::exception_check
    • Env::exception_clear
    • Env::exception_describe
    • Env::exception_occurred (#​517)
    • Env::is_same_object
    • Env::delete_local_ref
    • WeakRef::is_same_object
    • WeakRef::is_weak_ref_to_same_object
    • WeakRef::is_garbage_collected
  • Env::fatal_error is now guaranteed not to panic or allocate, but requires the error message to be encoded ahead of time. (#​480)

  • Env::get_native_interface has been removed since it's redundant and Env::get_raw is more consistent with other APIs.

  • Env::register_native_methods is now marked unsafe since it requires all the given function pointers to be valid and match corresponding Java method signatures (568)

  • get_object_class borrows the Env mutably because it creates a new local reference. (#​456)

  • get/set_*_field_unchecked have been marked as unsafe since they can lead to undefined behaviour if the given types don't match the field type (#​457 + #​629)

  • set_static_field takes a field name and signature as strings so the ID is looked up internally to ensure it's valid. (#​629)

  • Env::get/set/take_rust_field no longer require a mutable Env reference since they don't return any new local references to the caller (#​455)

  • Env::get_rust_field returns a MutexGuard<'local> instead of taking the &'env self lifetime (so you don't lose any &mut Env reference you have) (#​675)

  • Env::is_assignable_from and is_instance_of no longer requires a mutable Env reference, since they don't return any new local references to the caller

  • Env::new_weak_ref returns a Result<Weak> and Error::ObjectFreed if the reference is null or has already been freed (instead of Result<Option<Weak>>) (#​596)

  • Env::new_global_ref and ::new_local_ref may return Error::ObjectFreed in case a weak reference was given and the object has been freed. (#​596)

  • Env::with_local_frame can be used with a shared &Env reference since it doesn't return a new local reference. (#​673)

  • Env::with_local_frame_returning_local can now return any kind of local Reference, not just JObject

  • Env::new_object_unchecked now takes a Desc<JMethodID> for consistency/flexibility instead of directly taking a JMethodID

String APIs
  • JavaStr has been renamed MUTF8Chars (with a deprecated JavaStr alias) and is intended to be got via JString::mutf8_chars()
  • JavaStr/MUTF8Chars::from_env has been removed because it was unsound (it could cause undefined behavior and was not marked unsafe). Use JString::mutf8_chars instead. (#​510 / #​512)
  • JavaStr/MUTF8Chars::get_raw has been renamed to as_ptr. (#​510 / #​512)
  • JavaStr/MUTF8Chars, JNIStr, and JNIString no longer coerce to CStr, because using CStr::to_str will often have incorrect results. You can still get a CStr, but must use the new as_cstr method to do so. (#​510 / #​512)
  • All APIs that were accepting modified-utf8 string args via Into<JNIString>, now take AsRef<JNIStr> to avoid string copies every call. Considering that these strings are often literals for signatures or class names, most code can use jni_str!() to encode string literals at compile time, like env.find_class(jni_str!("java/lang/Foo")). (#​617, #​696)
  • JavaStr/MUTF8Chars and JString both implement Display and therefore ToString, making it even easier to get a Rust String.
  • Env::get_string performance was optimized by caching an expensive class lookup, and using a faster instanceof check. (#​531)
  • Env::get_string performance was later further optimized to avoid the need for runtime type checking (#​612)
  • Env::get_string has been deprecated in favor of JString::mutf8_chars and JString::to_string() or JString::try_to_string(env)
Class Loading APIs
  • The documentation for Env::find_class now recommends considering LoaderContext::load_class instead.
  • Desc<JClass>::lookup() is now based on LoaderContext::load_class (instead of Env::find_class), which checks for a thread context class loader by default.
  • Env::define_class takes a name: Option<> instead of having a separate define_unnamed_class API.
  • Env::define_class_bytearray was renamed to Env::define_class_jbyte and is identical to define_class except for taking a &[jbyte] slice instead of &[u8], which is a convenience if you have a JByteArray or AutoElements<JByteArray>.
  • Env::define_class[_jbyte] now takes a loader: AsRef<JClassLoader> instead of loader: &JObject.
java.lang APIs
  • JList is a simpler, transparent reference wrapper implementing Reference, like JObject, JClass, JString etc
  • JList::add returns the boolean returned by the Java API
  • JList::get and JList::remove no longer returns an Option since there's nothing special about getting a null from the Java List API.
  • JList::pop is deprecated since this doesn't map to standard Java List method.
  • JList::iter returns a JIterator instead of a JListIter
  • Env::get_list has been deprecated, in favor of JList::cast_local, or other generic Env cast_local/cast_global APIs.
  • Env::get_array_elements is deprecated in favor of JPrimitiveArray::get_elements
  • Env::get_array_elements_critical is deprecated in favor of JPrimitiveArray::get_elements_critical
  • Env::get_*_array_region and Env::set_*_array_region are deprecated in favor of JPrimitiveArray::get/set_region
  • Env::get_array_length is deprecated in favor of JPrimitiveArray::len and JObjectArray::len
  • Env::get/set_object_array_element are deprecated in favor of JObjectArray::get/set_element
  • Env::new_*_array methods for primitive array types (like JByteArray) take a &mut Env and a usize len, and the docs recommend using J<Type>Array::new() instead.
Miscellaneous
  • AutoElements[Critical]::discard() now takes ownership of the elements and drops them to release the pointer after setting the mode to NoCopyBack (#​645)
  • Mark MonitorGuard with #[must_use] to warn when the guard is dropped accidentally (#​676)
  • NativeMethod (used with Env::register_native_methods) is a now a transparent jni::sys::JNINativeWrapper wrapper with an unsafe ::from_raw_parts constructor.
  • All APIs that require a JNI signature (like Env::get_method_id, Env::call_method etc) now require a pre-parsed MethodSignature or FieldSignature type instead of a raw string. This enables compile-time signature parsing via the jni_sig! macro, and avoids runtime signature parsing costs. (#​714)
Dependencies
  • jni-sys dependency bumped to 0.4 (#​478)
Fixed
  • Env::get_string no longer leaks local references. (#​528, #​557)
  • Deadlocks on Windows when automatically detaching JNI when threads exit. Attachments are now tracked with fiber local storage so detachment happens without holding OS loader lock. (#​701)
Removed
  • JavaVM::attach_current_thread_as_daemon (and general support for 'daemon' threads) has been removed, since their semantics are inherently poorly defined and unsafe (the distinction relates to the poorly defined limbo state after calling JavaDestroyVM, where it becomes undefined to touch the JVM) (#​593)
  • The 'Executor' API has been removed (AttachGuard::with_env can be used instead) (#​570)
  • Env::from_raw, Env::from_raw_unchecked and Env::unsafe_clone have been removed, since the API no longer exposes the Env type by-value, it must always be borrowed from an AttachGuard. (#​570)
  • Error::NullDeref and Error::JavaVMMethodNotFound have been removed since they were unused.
  • JavaType::Method was removed since a method signature isn't a type, and all usage was being matched as unreachable or an error.
  • Env::define_unnamed_class was removed in favor of having the define_class[_jbyte] APIs take a name: Option instead.

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [jni](https://github.com/jni-rs/jni-rs) | dependencies | minor | `0.21` -> `0.22` | --- ### Release Notes <details> <summary>jni-rs/jni-rs (jni)</summary> ### [`v0.22.0`](https://github.com/jni-rs/jni-rs/blob/HEAD/CHANGELOG.md#0220--2026-02-17) [Compare Source](https://github.com/jni-rs/jni-rs/compare/v0.21.1...v0.22.0) ##### Added ##### JavaVM / Thread Attachment APIs - `JavaVM::singleton()` lets you acquire the `JavaVM` for the process when you know that the `JavaVM` singleton has been initialized ([#&#8203;595](https://github.com/jni-rs/jni-rs/pull/595)) - `JavaVM::is_thread_attached` can query whether the current thread is attached to the Java VM ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - `AttachGuard::from_unowned` added as a low-level (unsafe) way to represent a thread attachment with a raw `jni_sys::Env` pointer ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - `AttachConfig` exposes fine-grained control over thread attachment including `Thread` name, `ThreadGroup` and whether scoped or permanent. ([#&#8203;606](https://github.com/jni-rs/jni-rs/pull/606)) - `JavaVM::attach_current_thread_guard` is a low-level (unsafe) building block for attaching threads that exposes the `AttachGuard` and `AttachConfig` control. ([#&#8203;606](https://github.com/jni-rs/jni-rs/pull/606)) - `JavaVM::attach_current_thread_with_config` is a safe building block for attaching threads that hides the `AttachGuard` but exposes `AttachConfig` control. ([#&#8203;606](https://github.com/jni-rs/jni-rs/pull/606)) - `JavaVM::with_local_frame` added as method to borrow a `Env` that is already attached to the current thread, after pushing a new JNI stack frame ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570), [#&#8203;673](https://github.com/jni-rs/jni-rs/pull/673)) - `JavaVM::with_top_local_frame_frame` added to borrow a `Env` for the top JNI stack frame (i.e. without pushing a new JNI stack frame) ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570), [#&#8203;673](https://github.com/jni-rs/jni-rs/pull/673)) ##### Reference Type APIs - A `Reference` trait for all reference types like `JObject`, `JClass`, `JString`, enabling `Global` and `Weak` to be generic over `Reference` and enabling safe casting and global caching of `JClass` references. ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) - `Reference::lookup_class` exposes a cached `Global<JClass>` for all `Reference` implementations ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `LoaderContext` + `LoaderContext::load_class` for loading classes, depending on available context ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::new_cast_global_ref` acts like `new_global_ref` with a type cast ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::cast_global` takes an owned `Global<From>` and returns an owned `Global<To>` ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::new_cast_local_ref` acts like `new_local_ref` with a type cast ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::cast_local` takes an owned local reference and returns a new type-cast wrapper (owned) ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::as_cast` or `Cast::new` borrows any `From: Reference` (global or local) reference and returns a `Cast<To>` that will Deref into `&To` ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::as_cast_unchecked` returns a `Cast<To>` like `as_cast()` but without a runtime `IsInstanceOf` check ([#&#8203;669](https://github.com/jni-rs/jni-rs/pull/669)) - `Env::as_cast_raw` or `Cast::from_raw` borrows a raw `jobject` reference and returns a `Cast<To>` that will Deref into `&To` - `Cast::new_unchecked` and `Cast::from_raw_unchecked` let you borrow a reference with an (`unsafe`) type cast, with no runtime check - `::cast_local()` methods as a convenience for all reference types, such as `let s = JString::cast_local(obj)` - `const` `null()` methods for all reference types. - `Global::null()` and `Weak::null()` construct null references (equivalent to `Default::default()`). ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) ##### JNI Environment APIs - `Env::call_nonvirtual_method` and `Env::call_nonvirtual_method_unchecked` to call non-virtual method. ([#&#8203;454](https://github.com/jni-rs/jni-rs/issues/454)) - `Env::to_reflected_method` and `Env::to_reflected_static_method` for retrieving the Java reflection API instance for a method or constructor. ([#&#8203;579](https://github.com/jni-rs/jni-rs/pull/579)) - `Env::throw_new_void` provides an easy way to throw an exception that's constructed with no message argument - `Env::new_object_type_array<E>` lets you you instantiate a `JObjectArray` with a given element type like `new_object_type_array::<JString>` - `Env::load_class` supports class lookups via the current `Thread` context class loader, with `FindClass` fallback. ([#&#8203;674](https://github.com/jni-rs/jni-rs/pull/674)) - `MethodSignature` and `FieldSignature` types have been added for compile-time parsed JNI method and field signatures ##### Native Method APIs - `EnvUnowned` is an FFI-safe type that can be used to capture a `jni_sys::Env` pointer given to native methods and give it a named lifetime (this can then be temporarily upgraded to a `&mut Env` reference via `EnvUnowned::with_env`) ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - `Outcome` is like a `Result` with the addition of a third `Panic()` variant, used for careful handling of errors in native methods. ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) - `EnvOutcome` represents an `EnvUnowned::with_env` outcome whose errors can be handle, with access to JNI, via an `ErrorPolicy`. ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) - `ErrorPolicy` is a trait with `on_error` and `on_panic` methods that can log native method errors or throw them as exceptions. ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) - `ThrowRuntimeExAndDefault` is an `ErrorPolicy` that throws any error as a `RuntimeException` (and returns a default value). ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) - `LogErrorAndDefault` is an `ErrorPolicy` that logs errors and returns a default value. ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) - `LogContextErrorAndDefault` is an `ErrorPolicy` that logs errors, with a given context string, and returns a default value. ([#&#8203;664](https://github.com/jni-rs/jni-rs/pull/664)) ##### String APIs - New functions for converting Rust `char` to and from Java `char` and `int` ([#&#8203;427](https://github.com/jni-rs/jni-rs/issues/427) / [#&#8203;434](https://github.com/jni-rs/jni-rs/pull/434)) - `JavaStr/MUTF8Chars`, `JNIStr`, and `JNIString` have several new methods and traits, most notably a `to_str` method that converts to a regular Rust string. ([#&#8203;510](https://github.com/jni-rs/jni-rs/issues/510) / [#&#8203;512](https://github.com/jni-rs/jni-rs/pull/512)) - `JNIStr` now implements `Debug`, `PartialEq`, `Eq`, `PartialOrd`, `Ord` and `Hash` ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615)) - `JNIString` now implements `Debug`, `PartialEq`, `Eq`, `PartialOrd`, `Ord`, `Hash` and `Clone` ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615)) - `PartialEq<&JNIStr> for JNIString` allows `JNIStr` and `JNIString` to be compared. ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615)) - `From<&JNIStr>` and `From<MUTF8Chars>` implementations for `JNIString`. ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615)) - `JNIStr::from_cstr` safely does a zero-copy cast of a `CStr` to a `JNIStr` after a `const` modified-utf8 encoding validation ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615),[#&#8203;617](https://github.com/jni-rs/jni-rs/pull/617), [#&#8203;715](https://github.com/jni-rs/jni-rs/pull/715)) - `JNIStr::to_bytes` gives access to a `&[u8]` slice over the bytes of a JNI string (like `CStr::to_bytes`) ([#&#8203;615](https://github.com/jni-rs/jni-rs/pull/615)) ##### java.lang APIs - `JClassLoader` as a `Reference` wrapper for `java.lang.ClassLoader` references ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `JCollection`, `JSet` and `JIterator` reference wrappers for `java.util.Collection`, `java.util.Set` and `java.util.Iterator` interfaces. ([#&#8203;621](https://github.com/jni-rs/jni-rs/pull/621)) - `JList::remove_item` for removing a given value, by-reference, from the list (instead of by index). ([#&#8203;713](https://github.com/jni-rs/jni-rs/pull/713)) - `JList::clear` allows a list to be cleared. ([#&#8203;713](https://github.com/jni-rs/jni-rs/pull/713)) - `JList::is_empty` checks if a list is empty. ([#&#8203;713](https://github.com/jni-rs/jni-rs/pull/713)) - `JList::as_collection` casts a list into a `JCollection` ([#&#8203;713](https://github.com/jni-rs/jni-rs/pull/713)) - `JObjectArray::new` lets you construct a `JObjectArray<E>` with strong element type parameterization, instead of `Env::new_object_array` ([#&#8203;657](https://github.com/jni-rs/jni-rs/pull/657) + [#&#8203;688](https://github.com/jni-rs/jni-rs/pull/688)) - `JObjectArray::get/set_element` let you get and set array elements as methods on the array. ([#&#8203;654](https://github.com/jni-rs/jni-rs/pull/654)) - `JPrimitiveArray::new` lets you construct a `JPrimitiveArray<E>`, consistent with `JObjectArray::new` ([#&#8203;688](https://github.com/jni-rs/jni-rs/pull/688)) - `JStackTraceElement` gives access to stack frame info within a stack trace, like filename, line number etc ([#&#8203;657](https://github.com/jni-rs/jni-rs/pull/657)) - `JString` now has `::new()`, `::from_str` and `::from_jni_str` constructor methods ([#&#8203;960](https://github.com/jni-rs/jni-rs/pull/690)) - `JThread` as a `Reference` wrapper for `java.lang.Thread` references ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `JThrowable::get_message` is a binding for `getMessage()` and gives easy access to an exception message - `JThrowable::get_stack_trace` is a binding for `getStackTrace()`, returning a `JObjectArray<JStackTraceElement>` ##### Macros - The `#[jni_mangle()]` attribute proc macro can export an `extern "system"` native method with a mangled name like "Java\_com\_example\_myMethod" so it can be automatically resolved within a shared library by the JVM ([#&#8203;693](https://github.com/jni-rs/jni-rs/pull/693)) - The `jni_str!` and `jni_cstr!` macros can encode a MUTF-8 `&'static JNIStr` or `&' static CStr` at compile time with full unicode support. ([#&#8203;696](https://github.com/jni-rs/jni-rs/pull/696)) - The `jni_sig!`, `jni_sig_str!`, `jni_sig_cstr!` and `jni_sig_jstr!` macros can parse and compile signatures like `(arg0: jint, arg1: JString) -> JString` into `MethodSignature` and `FieldSignature` descriptors or JNI string literals like "(ILjava/lang/String;)Ljava/lang/String;" ([#&#8203;697](https://github.com/jni-rs/jni-rs/pull/697)) - The `native_method!` macro binds a single native method to a Rust function with type safety and optionally exports it too. ([#&#8203;698](https://github.com/jni-rs/jni-rs/pull/698)) - The `bind_java_type!` macro can generate full Rust bindings for Java types (classes and interfaces) with fields, constructors, methods and native methods ([#&#8203;712](https://github.com/jni-rs/jni-rs/pull/712)) ##### Changed ##### JavaVM / Thread Attachment APIs - JNI version requirements are more explicit in the API and the crate now requires at least JNI `>= 1.4`. It needs `>= 1.2` so it can check for exceptions and needs `>= 1.4` to avoid runtime checks for direct byte buffers ([#&#8203;478](https://github.com/jni-rs/jni-rs/issues/478)) - At a low-level (unsafe), all thread attachments (not just scoped attachments) are now represented by an owned or unowned `AttachGuard` - `AttachGuard` usage is now considered `unsafe` since the type must be pinned to the stack (but that can't be guaranteed by the Rust type system alone). - To allow safe thread attachments (that ensure their `AttachGuard` is pinned to the stack), attachment APIs take a `FnOnce` whose `&mut Env` arg borrows from a hidden `AttachGuard` - `JavaVM::attach_current_thread` requests a permanent thread attachment (reducing cost of future `attach_current_thread()` calls) - `JavaVM::attach_current_thread_for_scope` requests a thread attachment that's detached after the given closure returns. - `JavaVM::get_java_vm_pointer` has been renamed `JavaVM::get_raw` for consistency. - `JavaVM::new` and `JavaVM::with_libjvm` now prevent libjvm from being unloaded. This isn't necessary for HotSpot, but other JVMs could crash if we don't do this. ([#&#8203;554](https://github.com/jni-rs/jni-rs/pull/554)) ##### Reference and Primitive Types - Make `from_raw()`, `into_raw()` and `null()` methods `const fn`. ([#&#8203;453](https://github.com/jni-rs/jni-rs/pull/453)) - Make `from_raw()` require an `Env` reference so the returned wrapper is guaranteed to have a local reference frame lifetime ([#&#8203;670](https://github.com/jni-rs/jni-rs/pull/670)) - `GlobalRef` and `WeakRef` have been renamed to `Global` and `Weak` and are now generic, parameterized, transparent wrappers over `'static` reference types like `Global<JClass<'static>>` (no longer an `Arc` holding a reference and VM pointer) ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) - `Global` and `Weak` no longer implement `Clone`, since JNI is required to create new reference (you'll need to explicitly use `env.new_global_ref`) - `Global` and `Weak` both implement `Default`, which will represent `::null()` references (equivalent to `JObject::null()`) - `Global::into_raw` replaces `Global::try_into_raw` and is infallible ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) - `AutoLocal` has been renamed to `Auto` with a deprecated type alias for `AutoLocal` to sign post the rename. - `AutoElements` was simplified to only be parameterized by one lifetime for the array reference, and accepts any `AsRef<JPrimitiveArray<T>>` as a reference. ([#&#8203;508](https://github.com/jni-rs/jni-rs/pull/508)) - `JObjectArray` supports generic element types like `JObjectArray<JString>` - `JavaType` was simplified to not capture object names or array details (like `ReturnType`) since these details don't affect `JValue` type checks and had a hidden cost that was redundant. - `JValueGen` has been removed. `JValue` and `JValueOwned` are now separate, unrelated, non-generic types. ([#&#8203;429](https://github.com/jni-rs/jni-rs/pull/429)) (Note: previously `JValue` and `JValueOwned` were type aliases for `JValueGen`, which was an internal type, but this design led to confusing error messages that made them harder to use) ##### JNI Environment APIs - `JNIEnv` is no longer a `#[transparent]` FFI-safe pointer wrapper and has been split into `EnvUnowned` (for FFI/native method args) and `Env` (non-FFI) ([#&#8203;634](https://github.com/jni-rs/jni-rs/pull/634)) - A `JNIEnv` type alias shows a verbose deprecation warning that explains how to migrate from `JNIEnv` to `EnvUnowned` and `Env` ([#&#8203;634](https://github.com/jni-rs/jni-rs/pull/634)) - `Env::get_version` has been renamed to `Env::version` ([#&#8203;478](https://github.com/jni-rs/jni-rs/issues/478)) - `Env` is no longer ever exposed in the API by-value can only be accessed by borrowing from a thread attachment `AttachGuard`. - `Env` implements runtime borrow checking to ensure new local references may only be associated with the top JNI stack frame - `JavaVM::get_env` is replaced by `JavaVM::get_env_attachment` which returns an `AttachGuard` if the current thread is attached. ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - The following functions are now infallible ([#&#8203;478](https://github.com/jni-rs/jni-rs/issues/478)): - `Env::version` - `Env::get_java_vm` - `Env::exception_check` - `Env::exception_clear` - `Env::exception_describe` - `Env::exception_occurred` ([#&#8203;517](https://github.com/jni-rs/jni-rs/issues/517)) - `Env::is_same_object` - `Env::delete_local_ref` - `WeakRef::is_same_object` - `WeakRef::is_weak_ref_to_same_object` - `WeakRef::is_garbage_collected` - `Env::fatal_error` is now guaranteed not to panic or allocate, but requires the error message to be encoded ahead of time. ([#&#8203;480](https://github.com/jni-rs/jni-rs/pull/480)) - `Env::get_native_interface` has been removed since it's redundant and `Env::get_raw` is more consistent with other APIs. - `Env::register_native_methods` is now marked `unsafe` since it requires all the given function pointers to be valid and match corresponding Java method signatures ([568](https://github.com/jni-rs/jni-rs/pull/568)) - `get_object_class` borrows the `Env` mutably because it creates a new local reference. ([#&#8203;456](https://github.com/jni-rs/jni-rs/pull/456)) - `get/set_*_field_unchecked` have been marked as unsafe since they can lead to undefined behaviour if the given types don't match the field type ([#&#8203;457](https://github.com/jni-rs/jni-rs/pull/457) + [#&#8203;629](https://github.com/jni-rs/jni-rs/pull/629)) - `set_static_field` takes a field name and signature as strings so the ID is looked up internally to ensure it's valid. ([#&#8203;629](https://github.com/jni-rs/jni-rs/pull/629)) - `Env::get/set/take_rust_field` no longer require a mutable `Env` reference since they don't return any new local references to the caller ([#&#8203;455](https://github.com/jni-rs/jni-rs/issues/455)) - `Env::get_rust_field` returns a `MutexGuard<'local>` instead of taking the `&'env self` lifetime (so you don't lose any `&mut Env` reference you have) ([#&#8203;675](https://github.com/jni-rs/jni-rs/pull/675)) - `Env::is_assignable_from` and `is_instance_of` no longer requires a mutable `Env` reference, since they don't return any new local references to the caller - `Env::new_weak_ref` returns a `Result<Weak>` and `Error::ObjectFreed` if the reference is null or has already been freed (instead of `Result<Option<Weak>>`) ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) - `Env::new_global_ref` and `::new_local_ref` may return `Error::ObjectFreed` in case a weak reference was given and the object has been freed. ([#&#8203;596](https://github.com/jni-rs/jni-rs/pull/596)) - `Env::with_local_frame` can be used with a shared `&Env` reference since it doesn't return a new local reference. ([#&#8203;673](https://github.com/jni-rs/jni-rs/pull/673)) - `Env::with_local_frame_returning_local` can now return any kind of local `Reference`, not just `JObject` - `Env::new_object_unchecked` now takes a `Desc<JMethodID>` for consistency/flexibility instead of directly taking a `JMethodID` ##### String APIs - `JavaStr` has been renamed `MUTF8Chars` (with a deprecated `JavaStr` alias) and is intended to be got via `JString::mutf8_chars()` - `JavaStr/MUTF8Chars::from_env` has been removed because it was unsound (it could cause undefined behavior and was not marked `unsafe`). Use `JString::mutf8_chars` instead. ([#&#8203;510](https://github.com/jni-rs/jni-rs/issues/510) / [#&#8203;512](https://github.com/jni-rs/jni-rs/pull/512)) - `JavaStr/MUTF8Chars::get_raw` has been renamed to `as_ptr`. ([#&#8203;510](https://github.com/jni-rs/jni-rs/issues/510) / [#&#8203;512](https://github.com/jni-rs/jni-rs/pull/512)) - `JavaStr/MUTF8Chars`, `JNIStr`, and `JNIString` no longer coerce to `CStr`, because using `CStr::to_str` will often have incorrect results. You can still get a `CStr`, but must use the new `as_cstr` method to do so. ([#&#8203;510](https://github.com/jni-rs/jni-rs/issues/510) / [#&#8203;512](https://github.com/jni-rs/jni-rs/pull/512)) - All APIs that were accepting modified-utf8 string args via `Into<JNIString>`, now take `AsRef<JNIStr>` to avoid string copies every call. Considering that these strings are often literals for signatures or class names, most code can use `jni_str!()` to encode string literals at compile time, like `env.find_class(jni_str!("java/lang/Foo"))`. ([#&#8203;617](https://github.com/jni-rs/jni-rs/pull/617), [#&#8203;696](https://github.com/jni-rs/jni-rs/pull/696)) - `JavaStr/MUTF8Chars` and `JString` both implement `Display` and therefore `ToString`, making it even easier to get a Rust `String`. - `Env::get_string` performance was optimized by caching an expensive class lookup, and using a faster instanceof check. ([#&#8203;531](https://github.com/jni-rs/jni-rs/pull/531)) - `Env::get_string` performance was later further optimized to avoid the need for runtime type checking ([#&#8203;612](https://github.com/jni-rs/jni-rs/pull/612)) - `Env::get_string` has been deprecated in favor of `JString::mutf8_chars` and `JString::to_string()` or `JString::try_to_string(env)` ##### Class Loading APIs - The documentation for `Env::find_class` now recommends considering `LoaderContext::load_class` instead. - `Desc<JClass>::lookup()` is now based on `LoaderContext::load_class` (instead of `Env::find_class`), which checks for a thread context class loader by default. - `Env::define_class` takes a `name: Option<>` instead of having a separate `define_unnamed_class` API. - `Env::define_class_bytearray` was renamed to `Env::define_class_jbyte` and is identical to `define_class` except for taking a `&[jbyte]` slice instead of `&[u8]`, which is a convenience if you have a `JByteArray` or `AutoElements<JByteArray>`. - `Env::define_class[_jbyte]` now takes a `loader: AsRef<JClassLoader>` instead of `loader: &JObject`. ##### java.lang APIs - `JList` is a simpler, transparent reference wrapper implementing `Reference`, like `JObject`, `JClass`, `JString` etc - `JList::add` returns the boolean returned by the Java API - `JList::get` and `JList::remove` no longer returns an `Option` since there's nothing special about getting a `null` from the Java `List` API. - `JList::pop` is deprecated since this doesn't map to standard Java `List` method. - `JList::iter` returns a `JIterator` instead of a `JListIter` - `Env::get_list` has been deprecated, in favor of `JList::cast_local`, or other generic `Env` `cast_local/cast_global` APIs. - `Env::get_array_elements` is deprecated in favor of `JPrimitiveArray::get_elements` - `Env::get_array_elements_critical` is deprecated in favor of `JPrimitiveArray::get_elements_critical` - `Env::get_*_array_region` and `Env::set_*_array_region` are deprecated in favor of `JPrimitiveArray::get/set_region` - `Env::get_array_length` is deprecated in favor of `JPrimitiveArray::len` and `JObjectArray::len` - `Env::get/set_object_array_element` are deprecated in favor of `JObjectArray::get/set_element` - `Env::new_*_array` methods for primitive array types (like `JByteArray`) take a `&mut Env` and a `usize` len, and the docs recommend using `J<Type>Array::new()` instead. ##### Miscellaneous - `AutoElements[Critical]::discard()` now takes ownership of the elements and drops them to release the pointer after setting the mode to `NoCopyBack` ([#&#8203;645](https://github.com/jni-rs/jni-rs/pull/645)) - Mark `MonitorGuard` with `#[must_use]` to warn when the guard is dropped accidentally ([#&#8203;676](https://github.com/jni-rs/jni-rs/pull/676)) - `NativeMethod` (used with `Env::register_native_methods`) is a now a transparent `jni::sys::JNINativeWrapper` wrapper with an `unsafe` `::from_raw_parts` constructor. - All APIs that require a JNI signature (like `Env::get_method_id`, `Env::call_method` etc) now require a pre-parsed `MethodSignature` or `FieldSignature` type instead of a raw string. This enables compile-time signature parsing via the `jni_sig!` macro, and avoids runtime signature parsing costs. ([#&#8203;714](https://github.com/jni-rs/jni-rs/pull/714)) ##### Dependencies - `jni-sys` dependency bumped to `0.4` ([#&#8203;478](https://github.com/jni-rs/jni-rs/issues/478)) ##### Fixed - `Env::get_string` no longer leaks local references. ([#&#8203;528](https://github.com/jni-rs/jni-rs/pull/528), [#&#8203;557](https://github.com/jni-rs/jni-rs/pull/557)) - Deadlocks on Windows when automatically detaching JNI when threads exit. Attachments are now tracked with fiber local storage so detachment happens without holding OS loader lock. ([#&#8203;701](https://github.com/jni-rs/jni-rs/issues/701)) ##### Removed - `JavaVM::attach_current_thread_as_daemon` (and general support for 'daemon' threads) has been removed, since their semantics are inherently poorly defined and unsafe (the distinction relates to the poorly defined limbo state after calling `JavaDestroyVM`, where it becomes undefined to touch the JVM) ([#&#8203;593](https://github.com/jni-rs/jni-rs/pull/593)) - The 'Executor' API has been removed (`AttachGuard::with_env` can be used instead) ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - `Env::from_raw`, `Env::from_raw_unchecked` and `Env::unsafe_clone` have been removed, since the API no longer exposes the `Env` type by-value, it must always be borrowed from an `AttachGuard`. ([#&#8203;570](https://github.com/jni-rs/jni-rs/pull/570)) - `Error::NullDeref` and `Error::JavaVMMethodNotFound` have been removed since they were unused. - `JavaType::Method` was removed since a method signature isn't a type, and all usage was being matched as unreachable or an error. - `Env::define_unnamed_class` was removed in favor of having the `define_class[_jbyte]` APIs take a `name: Option` instead. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4yNy4wIiwidXBkYXRlZEluVmVyIjoiNDIuMjcuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Update Rust crate jni to 0.22
All checks were successful
Forgejo-Templates/Rust-Multi-Platform-Project/pipeline/pr-main This commit looks good
Forgejo-Templates/Rust-Multi-Platform-Project/pipeline/head This commit looks good
572dbafcd5
All checks were successful
Forgejo-Templates/Rust-Multi-Platform-Project/pipeline/pr-main This commit looks good
Forgejo-Templates/Rust-Multi-Platform-Project/pipeline/head This commit looks good
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin renovate/jni-0.x:renovate/jni-0.x
git switch renovate/jni-0.x

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff renovate/jni-0.x
git switch renovate/jni-0.x
git rebase main
git switch main
git merge --ff-only renovate/jni-0.x
git switch renovate/jni-0.x
git rebase main
git switch main
git merge --no-ff renovate/jni-0.x
git switch main
git merge --squash renovate/jni-0.x
git switch main
git merge --ff-only renovate/jni-0.x
git switch main
git merge renovate/jni-0.x
git push origin main
Sign in to join this conversation.
No description provided.