23 KiB
Changelog
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.
Unreleased
0.21.1 — 2023-03-08
Fixes
- Compilation is fixed for architectures with a C ABI that has unsigned
chartypes. (#419)
0.21.0 — 2023-02-13
This release makes extensive breaking changes in order to improve safety. Most projects that use this library will need to be changed. Please see the migration guide.
Added
JavaStr::into_raw()which drops theJavaStrand releases ownership of the raw string pointer (#374)JavaStr::from_raw()which takes ownership of a raw string pointer to create aJavaStr(#374)JNIEnv::get_string_uncheckedis a cheaper,unsafealternative toget_stringthat doesn't check the given object is ajava.lang.Stringinstance. (#328)WeakRefandJNIEnv#new_weak_ref. (#304)define_class_bytearraymethod that takes anAutoElements<jbyte>rather than a&[u8](#244)JObjectnow has anas_rawmethod that borrows theJObjectinstead of taking ownership likeinto_raw. Needed becauseJObjectno longer has theCopytrait. (#392)JavaVM::destroy()(unsafe) as a way to try and unload aJavaVMon supported platforms (#391)JavaVM::detach_current_thread()(unsafe) as a way to explicitly detach a thread (normally this is automatic on thread exit). Needed to detach daemon threads manually if usingJavaVM::destroy()(#391)JPrimitiveArray<T: TypeArray>and type-specific aliases likeJByteArray,JIntArrayetc now provide safe, reference wrappers for thesystypesjarrayandjbyteArrayetc with a lifetime likeJObject(#400)JObjectArrayprovides a reference wrapper for ajobjectArraywith a lifetime likeJObject. (#400)AutoElementsandAutoElementsCritical(previouslyAutoArray/AutoPrimitiveArray) implementDeref<Target=[T]>andDerefMutso array elements can be accessed via slices without needing additionalunsafecode. (#400)AsJArrayRawtrait which enablesJNIEnv::get_array_length()to work withJPrimitiveArrayorJObjectArraytypes (#400)InitArgsBuildernow hastry_optionandoption_encodedmethods. (#414)
Changed
JNIEnv::get_stringchecks that the given object is ajava.lang.Stringinstance to avoid undefined behaviour from the JNI implementation potentially aborting the program. (#328)JNIEnv::call_*method_uncheckedwas markedunsafe, as passing improper argument types, or a bad number of arguments, can cause a JVM crash. (#385)- The
JNIEnv::new_object_uncheckedfunction now takes arguments as&[jni::sys::jvalue]to avoid allocating, putting it inline with changes toJniEnv::call_*_uncheckedfrom 0.20.0 (#382) - The
get_superclassfunction now returns an Option instead of a null pointer if the class has no superclass (#151) - The
invocationfeature now locates the JVM implementation dynamically at runtime (via thejava-locatorcrate by default) instead of linking with the JVM at build time (#293) - Most
JNIEnvmethods now require&mut self. This improves safety by preventingJObjects from getting an invalid lifetime. Most native method implementations (that is,#[no_mangle] extern "system" fns) must now make theJNIEnvparametermut. See the example on the crate documentation. (#392) JByteBuffer,JClass,JNIEnv,JObject,JString, andJThrowableno longer have theCloneorCopytraits. This improves safety by preventing object references from being used after the JVM deletes them. Most functions that take one of these types as a parameter (exceptextern fns that are directly called by the JVM) should now borrow it instead, e.g.&JObjectinstead ofJObject. (#392)AutoLocalis now generic in the type of object reference (JString, etc). (#392)- The closure passed to
JNIEnv::with_local_framemust now take a&mut JNIEnvparameter, which has a different lifetime. This improves safety by preventing local references from escaping the closure, which would cause a use-after-free bug.Executor::with_attachedandExecutor::with_attached_capacityhave been similarly changed. (#392) - The closure passed to
JNIEnv::with_local_framecan now return a genericResult<T, E>so long as the error implementsFrom<jni::errors::Error>(#399) JNIEnv::with_local_framenow returns the same type that the given closure returns (#399)JNIEnv::with_local_frameno longer supports returning a local reference directly to the calling scope (seewith_local_frame_returning_local) (#399)Executor::with_attachedandExecutor::with_attached_capacityhave been changed in the same way asJNIEnv::with_local_frame(they are thin wrappers) (#399)Desc,JNIEnv::pop_local_frame, andTypeArrayare nowunsafe. (#392)- The
Desctrait now has an associated typeOutput. Many implementations now returnAutoLocal, so if you callDesc::lookupyourself and then callas_rawon the returned object, make sure theAutoLocalisn't dropped too soon (see theDesc::lookupdocumentation for examples). (#392) - The
Desc<JClass>trait is no longer implemented forJObjector&JObject. The previous implementation that called.get_object_class()was surprising and a simpler cast would make it easy to mistakenly pass instances where a class is required. (#118) - Named lifetimes in the documentation have more descriptive names (like
'localinstead of'a). The new naming convention is explained in theJNIEnvdocumentation. (#392) - Object reference types (
JObject,JClass,AutoLocal,GlobalRef, etc) now implementAsRef<JObject>andDeref<Target = JObject>. Typed wrappers likeJClassalso implementInto<JObject>, butGlobalRefdoes not. (#392) - Most
JListandJMapmethods now require a&mut JNIEnvparameter.JListIterandJMapIterno longer implementIterator, and instead have anextmethod that requires a&mut JNIEnvparameter (usewhile letloops instead offor). (#392) JValuehas been changed in several ways: (#392)- It is now a generic type named
JValueGen.JValueis now a type alias forJValueGen<&JObject>, that is, it borrows an object reference.JValueOwnedis a type alias forJValueGen<JObject>, that is, it owns an object reference. JValueOwneddoes not have theCopytrait.- The
to_jnimethod is now namedas_jni, and it borrows theJValueGeninstead of taking ownership. JObjectcan no longer be converted directly toJValue, which was commonly done when calling Java methods or constructors. Instead ofobj.into(), use(&obj).into().
- It is now a generic type named
- All
JNIEnvarray APIs now work in terms ofJPrimitiveArrayandJObjectArray(reference wrappers with a lifetime) instead ofsystypes likejarrayandjbyteArray(#400) AutoArrayandAutoPrimitiveArrayhave been renamedAutoElementsandAutoElementsCriticalto show their connection and differentiate from newJPrimitiveArrayAPI (#400)get_primitive_array_criticalis nowunsafeand has been renamed toget_array_elements_critical(consistent with the rename ofAutoPrimitiveArray) with more detailed safety documentation (#400)get_array_elementsis now alsounsafe(for many of the same reasons asget_array_elements_critical) and has detailed safety documentation (#400)AutoArray/AutoArrayCritical::size()has been replaced with.len()which can't fail and returns ausize(#400)- The
TypeArraytrait is now a private / sealed trait, that is considered to be an implementation detail for theAutoArrayAPI. JvmErrorhas several more variants and is nownon_exhaustive. (#414)InitArgsBuilder::optionraises an error on Windows if the string is too long. The limit is currently 1048576 bytes. (#414)
Fixed
- Trying to use an object reference after it has been deleted now causes a compile error instead of undefined behavior. As a result, it is now safe to use
AutoLocal,JNIEnv::delete_local_ref, andJNIEnv::with_local_frame. (Most of the limitations added in #392, listed above, were needed to make this work.) (#381, #392) - Class lookups via the
Desctrait now returnAutoLocals, which prevents them from leaking. (#109, #392) InitArgsBuilder::optionproperly encodes non-ASCII characters on Windows. (#414)
Removed
get_string_utf_charsandrelease_string_utf_charsfromJNIEnv(SeeJavaStr::into_raw()andJavaStr::from_raw()instead) (#372)- All
JNIEnv::get_<type>_array_elements()methods have been removed as redundant since they would all be equivalent toget_array_elements()with the introduction ofJPrimitiveArray(#400)
0.20.0 — 2022-10-17
Added
Defaulttrait implemented forJObject,JString,JClass, andJByteBuffer(#199)Debugtrait implemented forJavaVM,GlobalRef,GlobalRefGuard,JStaticMethodIDandReleaseMode(#345)ReturnTypefor specifying object return types without a String allocation. (#329)
Changed
- The
release_string_utf_charsfunction has been marked as unsafe. (#334) - Mark
JNIEnv::new_direct_byte_bufferasunsafe(#320) JNIEnv::new_direct_byte_buffernow takes a raw pointer and size instead of a slice (#351 and #364)JNIEnv::direct_buffer_addressreturns a raw pointer instead of a slice (#364)- The lifetime of
AutoArrayis no longer tied to the lifetime of a particularJNIEnvreference. (#302) - Relaxed lifetime restrictions on
JNIEnv::new_local_ref. Now it can be used to create a local reference from a global reference. (#301 / #319) JMethodIDandJStaticMethodIDimplementSend+Syncand no longer has a lifetime parameter, making method IDs cacheable (with a documented 'Safety' note about ensuring they remain valid). (#346)JFieldIDandJStaticFieldIDimplementSend+Syncand no longer has a lifetime parameter, making field IDs cacheable (with a documented 'Safety' note about ensuring they remain valid). (#346)- The
call_*_method_uncheckedfunctions now takejni:sys::jvaluearguments to avoid allocating aVecon each call to map + collectJValues assys:jvalues (#329) - The
Fromtrait implementations convertingjni_systypes likejobjecttoJObjecthave been replaced withunsafe::from_rawfunctions and corresponding::into_rawmethods. Existing::into_innerAPIs were renamed::into_rawfor symmetry. (#197) - The APIs
JNIEnv::set_rust_field,JNIEnv::get_rust_fieldandJNIEnv::take_rust_fieldhave been marked asunsafe(#219)
0.19.0 — 2021-01-24
Added
AutoArrayand genericget_array_elements(), along withget_<type>_array_elementshelpers. (#287)size()method toAutoArrayandAutoPrimitiveArray. (#278 / #287)discard()method toAutoArrayandAutoPrimitiveArray. (#275 / #287)
Changed
- Removed AutoPrimitiveArray::commit(). (#290)
AutoByte/PrimitiveArray.commit()now returnsResult. (#275)- Removed methods get/release/commit_byte/primitive_array_{elements|critical}. (#281)
- Renamed methods get_auto_byte/long/primitive_array_{elements|critical} to get_byte/long/primitive_array_{elements|critical}. (#281)
0.18.0 — 2020-09-23
Added
JNIEnv#define_unnamed_classfunction 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).- Implemented Copy for JNIEnv (#255).
repr(transparent)attribute to JavaVM struct (#259)
Changed
- Switch from
error-chaintothiserror, making all errorsSend. Also, support all JNI errors in thejni_error_code_to_resultfunction and add more information to theInvalidArgListerror. (#242)
0.17.0 — 2020-06-30
Added
- Get/ReleaseByteArrayElements, and Get/ReleasePrimitiveArrayCritical. (#237)
0.16.0 — 2020-02-28
Fixed
- Java VM instantiation with some MacOS configurations. (#220, #229, #230).
0.15.0 — 2020-02-28
Added
- Ability to pass object wrappers that are convertible to
JObjectas arguments to the majority of JNIEnv methods without explicit conversion. (#213) JNIEnv#is_same_objectimplementation. (#213)JNIEnv#register_native_methods. (#214)- Conversion from
Into<JObject>toJValue::Object.
Fixed
- Passing
nullas class loader todefine_classmethod now allowed according to the JNI specification. (#225)
0.14.0 — 2019-10-31
Changed
- Relaxed some lifetime restrictions in JNIEnv to support the case when method, field ids; and global references to classes have a different (larger) lifetime than JNIEnv. (#209)
0.13.1 — 2019-08-22
Changed
- Various documentation improvements.
0.13.0 — 2019-07-05
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.
⚠️ If your code attaches native threads — make sure to check the updated documentation of JavaVM to learn about the new features!
Added
JavaVM::attach_current_thread_permanentlymethod, which attaches the current thread and detaches it when the thread finishes. Daemon threads attached withJavaVM::attach_current_thread_as_daemonalso automatically detach themselves when finished. The number of currently attached threads may be acquired usingJavaVM::threads_attachedmethod. (#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)
Changed
- The default JNI API version in
InitArgsBuilderfrom V1 to V8. (#178) - Extended the lifetimes of
AutoLocalto make it more flexible. (#190) - Default exception type from checked
java.lang.Exceptionto uncheckedjava.lang.RuntimeException. It is used implicitly whenJNIEnv#throwis invoked with exception message:env.throw("Exception message"); however, for efficiency reasons, it is recommended to specify the exception type explicitly and usethrow_new:env.throw_new(exception_type, "Exception message"). (#194)
Fixed
- Native threads attached with
JavaVM::attach_current_thread_as_daemonnow automatically detach themselves on exit, preventing Java Thread leaks. (#179) - Local reference leaks in
JList,JMapandJMapIter. (#190, #191)
0.12.3
Added
From<jboolean>implementation forJValue(#173)Debugtrait for InitArgsBuilder. (#175)InitArgsBuilder#optionsreturning the collected JVM options. (#177)
0.12.2
Changed
- Updated documentation of GetXArrayRegion methods (#169)
- Improved ABI compatibility on various platforms (#170)
0.12.1
This release does not bring code changes.
Changed
- Updated project documentation.
0.12.0
Changed
JString,JMapandJavaStrand their respective iterators now require an extra lifetime so that they can now work with&'b JNIEnv<'a>, where'a: 'b.
0.11.0
Highlights
This release brings various improvements and fixes, outlined below. The most notable changes are:
nullis no longer represented as anErrwith error kindNullPtrif it is a value of some nullable Java reference (not an indication of an error). Related issues: #136, #148, #163.unsafemethods, providing a low-level API similar to JNI, has been marked safe and renamed to have_uncheckedsuffix. 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.
Added
- Invocation API support on Windows and AppVeyor CI (#149)
Changed
-
push_local_frame,delete_global_refandrelease_string_utf_charsno longer check for exceptions as they are safe to call if there is a pending exception (#124):push_local_framewill now work in case of pending exceptions — as the spec requires; and fail in case of allocation errorsdelete_global_refandrelease_string_utf_charswon't print incorrect log messages
-
Rename some macros to better express their intent (see #123):
- Rename
jni_calltojni_non_null_callas it checks the return value to be non-null. - Rename
jni_non_null_call(which may return nulls) tojni_non_void_call.
- Rename
-
A lot of public methods of
JNIEnvhave been marked as safe, all unsafe code has been isolated inside internal macros. Methods with_unsafesuffixes have been renamed and now have_uncheckedsuffixes (#140) -
from_strmethod of theJavaTypehas been replaced by theFromStrimplementation -
Implemented Sync for GlobalRef (#102).
-
Improvements in macro usage for JNI methods calls (#136):
call_static_method_uncheckedandget_static_field_uncheckedmethods are allowed to return NULL object- Added checking for pending exception to the
call_static_method_uncheckedmethod (eliminated WARNING messages in log)
-
Further improvements in macro usage for JNI method calls (#150):
- The new_global_ref() and new_local_ref() functions are allowed to work with NULL objects according to specification.
- Fixed the family of functions new_direct_byte_buffer(), get_direct_buffer_address() and get_direct_buffer_capacity() by adding checking for null and error codes.
- Increased tests coverage for JNIEnv functions.
-
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).
Fixed
- The issue with early detaching of a thread by nested AttachGuard. (#139)
0.10.2
Added
JavaVM#get_java_vm_pointerto retrieve a JavaVM pointer (#98)- This changelog and other project documents (#106)
Changed
- The project is moved to an organization (#104)
- Updated versions of dependencies (#105)
- Improved project documents (#107)
Fixed
- Crate type of a shared library with native methods
must be
cdylib(#100)
0.10.1
- No changes has been made to the Changelog until this release.