All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
Default
trait implemented for JObject
, JString
, JClass
, and JByteBuffer
(#199)Debug
trait implemented for JavaVM
, GlobalRef
, GlobalRefGuard
, JStaticMethodID
and ReleaseMode
(#345)ReturnType
for specifying object return types without a String allocation. (#329)release_string_utf_chars
function has been marked as unsafe. (#334)JNIEnv::new_direct_byte_buffer
as unsafe
(#320)JNIEnv::new_direct_byte_buffer
now takes a raw pointer and size instead of a slice (#351 and #364)JNIEnv::direct_buffer_address
returns a raw pointer instead of a slice (#364)AutoArray
is no longer tied to the lifetime of a particular JNIEnv
reference. (#302)JNIEnv::new_local_ref
. Now it can be used to create a local reference from a global reference. (#301 / #319)JMethodID
and JStaticMethodID
implement Send
+ Sync
and no longer has a lifetime parameter, making method IDs cacheable (with a documented ‘Safety’ note about ensuring they remain valid). (#346)JFieldID
and JStaticFieldID
implement Send
+ Sync
and no longer has a lifetime parameter, making field IDs cacheable (with a documented ‘Safety’ note about ensuring they remain valid). (#346)call_*_method_unchecked
functions now take jni:sys::jvalue
arguments to avoid allocating a Vec
on each call to map + collect JValue
s as sys:jvalue
s (#329)From
trait implementations converting jni_sys
types like jobject
to JObject
have been replaced with unsafe
::from_raw
functions and corresponding ::into_raw
methods. Existing ::into_inner
APIs were renamed ::into_raw
for symmetry. (#197)JNIEnv::set_rust_field
, JNIEnv::get_rust_field
and JNIEnv::take_rust_field
have been marked as unsafe
(#219)AutoArray
and generic get_array_elements()
, along with get_<type>_array_elements
helpers. (#287)size()
method to AutoArray
and AutoPrimitiveArray
. (#278 / #287)discard()
method to AutoArray
and AutoPrimitiveArray
. (#275 / #287)AutoByte/PrimitiveArray.commit()
now returns Result
. (#275)JNIEnv#define_unnamed_class
function that allows loading a class without specifying its name. The name is inferred from the class data. (#246)SetStatic<type>Field
. (#248)TryFrom<JValue>
for types inside JValue variants (#264).repr(transparent)
attribute to JavaVM struct (#259)error-chain
to thiserror
, making all errors Send
. Also, support all JNI errors in the jni_error_code_to_result
function and add more information to the InvalidArgList
error. (#242)JObject
as arguments to the majority of JNIEnv methods without explicit conversion. (#213)JNIEnv#is_same_object
implementation. (#213)JNIEnv#register_native_methods
. (#214)Into<JObject>
to JValue::Object
.null
as class loader to define_class
method now allowed according to the JNI specification. (#225)0.13 brings major improvements in thread management, allowing to attach the native threads permanently and safely; Executor
for extra convenience and safety; and other improvements and fixes.
:warning: If your code attaches native threads — make sure to check the updated documentation of JavaVM to learn about the new features!
JavaVM::attach_current_thread_permanently
method, which attaches the current thread and detaches it when the thread finishes. Daemon threads attached with JavaVM::attach_current_thread_as_daemon
also automatically detach themselves when finished. The number of currently attached threads may be acquired using JavaVM::threads_attached
method. (#179, #180)Executor
— a simple thread attachment manager which helps to safely execute a closure in attached thread context and to automatically free created local references at closure exit. (#186)InitArgsBuilder
from V1 to V8. (#178)AutoLocal
to make it more flexible. (#190)java.lang.Exception
to unchecked java.lang.RuntimeException
. It is used implicitly when JNIEnv#throw
is invoked with exception message: env.throw("Exception message")
; however, for efficiency reasons, it is recommended to specify the exception type explicitly and use throw_new
: env.throw_new(exception_type, "Exception message")
. (#194)JavaVM::attach_current_thread_as_daemon
now automatically detach themselves on exit, preventing Java Thread leaks. (#179)JList
, JMap
and JMapIter
. (#190, #191)From<jboolean>
implementation for JValue
(#173)Debug
trait for InitArgsBuilder. (#175)InitArgsBuilder#options
returning the collected JVM options. (#177)This release does not bring code changes.
JString
, JMap
and JavaStr
and their respective iterators now require an extra lifetime so that they can now work with &'b JNIEnv<'a>
, where 'a: 'b
.This release brings various improvements and fixes, outlined below. The most notable changes are:
null
is no longer represented as an Err
with error kind NullPtr
if it is a value of some nullable Java reference (not an indication of an error). Related issues: #136, #148, #163.unsafe
methods, providing a low-level API similar to JNI, has been marked safe and renamed to have _unchecked
suffix. Such methods can be used to implement caching of class references and method IDs to improve performance in loops and frequently called Java callbacks. If you have such, check out the docs and one of early usages of this feature.push_local_frame
, delete_global_ref
and release_string_utf_chars
no longer check for exceptions as they are safe to call if there is a pending exception (#124):
push_local_frame
will now work in case of pending exceptions — as the spec requires; and fail in case of allocation errorsdelete_global_ref
and release_string_utf_chars
won't print incorrect log messagesRename some macros to better express their intent (see #123):
jni_call
to jni_non_null_call
as it checks the return value to be non-null.jni_non_null_call
(which may return nulls) to jni_non_void_call
.A lot of public methods of JNIEnv
have been marked as safe, all unsafe code has been isolated inside internal macros. Methods with _unsafe
suffixes have been renamed and now have _unchecked
suffixes (#140)
from_str
method of the JavaType
has been replaced by the FromStr
implementation
Implemented Sync for GlobalRef (#102).
Improvements in macro usage for JNI methods calls (#136):
call_static_method_unchecked
and get_static_field_unchecked
methods are allowed to return NULL objectcall_static_method_unchecked
method (eliminated WARNING messages in log)Further improvements in macro usage for JNI method calls (#150):
Implemented Clone for JNIEnv (#147).
The get_superclass(), get_field_unchecked() and get_object_array_element() are allowed to return NULL object according to the specification (#163).
JavaVM#get_java_vm_pointer
to retrieve a JavaVM pointer (#98)cdylib
(#100)