1# Changelog 2 3All notable changes to this project will be documented in this file. 4 5The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 8<!-- Use the following sections from the spec: http://keepachangelog.com/en/1.0.0/ 9 - Added for new features. 10 - Changed for changes in existing functionality. 11 - Deprecated for soon-to-be removed features. 12 - Removed for now removed features. 13 - Fixed for any bug fixes. 14 - Security in case of vulnerabilities. --> 15 16## [Unreleased] 17 18 19## [0.20.0] — 2022-10-17 20 21### Added 22- `Default` trait implemented for `JObject`, `JString`, `JClass`, and `JByteBuffer` ([#199](https://github.com/jni-rs/jni-rs/issues/199)) 23- `Debug` trait implemented for `JavaVM`, `GlobalRef`, `GlobalRefGuard`, `JStaticMethodID` and `ReleaseMode` ([#345](https://github.com/jni-rs/jni-rs/pull/345)) 24- `ReturnType` for specifying object return types without a String allocation. ([#329](https://github.com/jni-rs/jni-rs/issues/329)) 25 26### Changed 27- The `release_string_utf_chars` function has been marked as unsafe. ([#334](https://github.com/jni-rs/jni-rs/pull/334)) 28- Mark `JNIEnv::new_direct_byte_buffer` as `unsafe` ([#320](https://github.com/jni-rs/jni-rs/pull/320)) 29- `JNIEnv::new_direct_byte_buffer` now takes a raw pointer and size instead of a slice ([#351](https://github.com/jni-rs/jni-rs/pull/351) and [#364](https://github.com/jni-rs/jni-rs/pull/364)) 30- `JNIEnv::direct_buffer_address` returns a raw pointer instead of a slice ([#364](https://github.com/jni-rs/jni-rs/pull/364)) 31- The lifetime of `AutoArray` is no longer tied to the lifetime of a particular `JNIEnv` reference. ([#302](https://github.com/jni-rs/jni-rs/issues/302)) 32- Relaxed lifetime restrictions on `JNIEnv::new_local_ref`. Now it can be used to create a local 33 reference from a global reference. ([#301](https://github.com/jni-rs/jni-rs/issues/301) / [#319](https://github.com/jni-rs/jni-rs/pull/319)) 34- `JMethodID` and `JStaticMethodID` implement `Send` + `Sync` and no longer has a lifetime parameter, making method 35 IDs cacheable (with a documented 'Safety' note about ensuring they remain valid). ([#346](https://github.com/jni-rs/jni-rs/pull/346)) 36- `JFieldID` and `JStaticFieldID` implement `Send` + `Sync` and no longer has a lifetime parameter, making field 37 IDs cacheable (with a documented 'Safety' note about ensuring they remain valid). ([#346](https://github.com/jni-rs/jni-rs/pull/365)) 38- The `call_*_method_unchecked` functions now take `jni:sys::jvalue` arguments to avoid allocating 39 a `Vec` on each call to map + collect `JValue`s as `sys:jvalue`s ([#329](https://github.com/jni-rs/jni-rs/issues/329)) 40- The `From` trait implementations converting `jni_sys` types like `jobject` to `JObject` have been replaced 41 with `unsafe` `::from_raw` functions and corresponding `::into_raw` methods. Existing `::into_inner` APIs were 42 renamed `::into_raw` for symmetry. ([#197](https://github.com/jni-rs/jni-rs/issues/197)) 43- The APIs `JNIEnv::set_rust_field`, `JNIEnv::get_rust_field` and `JNIEnv::take_rust_field` have been marked as `unsafe` ([#219](https://github.com/jni-rs/jni-rs/issues/219)) 44 45## [0.19.0] — 2021-01-24 46 47### Added 48- `AutoArray` and generic `get_array_elements()`, along with `get_<type>_array_elements` helpers. (#287) 49- `size()` method to `AutoArray` and `AutoPrimitiveArray`. (#278 / #287) 50- `discard()` method to `AutoArray` and `AutoPrimitiveArray`. (#275 / #287) 51 52### Changed 53- Removed AutoPrimitiveArray::commit(). (#290) 54- `AutoByte/PrimitiveArray.commit()` now returns `Result`. (#275) 55- Removed methods get/release/commit_byte/primitive_array_{elements|critical}. (#281) 56- Renamed methods get_auto_byte/long/primitive_array_{elements|critical} to 57 get_byte/long/primitive_array_{elements|critical}. (#281) 58 59## [0.18.0] — 2020-09-23 60 61### Added 62- `JNIEnv#define_unnamed_class` function that allows loading a class without 63 specifying its name. The name is inferred from the class data. (#246) 64- `SetStatic<type>Field`. (#248) 65- `TryFrom<JValue>` for types inside JValue variants (#264). 66- Implemented Copy for JNIEnv (#255). 67- `repr(transparent)` attribute to JavaVM struct (#259) 68 69### Changed 70- Switch from `error-chain` to `thiserror`, making all errors `Send`. Also, support all JNI errors 71 in the `jni_error_code_to_result` function and add more information to the `InvalidArgList` 72 error. ([#242](https://github.com/jni-rs/jni-rs/pull/242)) 73 74## [0.17.0] — 2020-06-30 75 76### Added 77- Get/ReleaseByteArrayElements, and Get/ReleasePrimitiveArrayCritical. (#237) 78 79## [0.16.0] — 2020-02-28 80 81### Fixed 82- Java VM instantiation with some MacOS configurations. (#220, #229, #230). 83 84## [0.15.0] — 2020-02-28 85 86### Added 87- Ability to pass object wrappers that are convertible to `JObject` as arguments to the majority 88 of JNIEnv methods without explicit conversion. (#213) 89- `JNIEnv#is_same_object` implementation. (#213) 90- `JNIEnv#register_native_methods`. (#214) 91- Conversion from `Into<JObject>` to `JValue::Object`. 92 93### Fixed 94- Passing `null` as class loader to `define_class` method now allowed according 95 to the JNI specification. (#225) 96 97## [0.14.0] — 2019-10-31 98 99### Changed 100- Relaxed some lifetime restrictions in JNIEnv to support the case when 101 method, field ids; and global references to classes 102 have a different (larger) lifetime than JNIEnv. (#209) 103 104## [0.13.1] — 2019-08-22 105 106### Changed 107- Various documentation improvements. 108 109## [0.13.0] — 2019-07-05 110 1110.13 brings major improvements in thread management, allowing to attach the native threads 112permanently and safely; `Executor` for extra convenience and safety; and other 113improvements and fixes. 114 115:warning: If your code attaches native threads — make sure to check the updated documentation 116of [JavaVM](https://docs.rs/jni/0.13.0/jni/struct.JavaVM.html) to learn about the new features! 117 118### Added 119- `JavaVM::attach_current_thread_permanently` method, which attaches the current 120 thread and detaches it when the thread finishes. Daemon threads attached 121 with `JavaVM::attach_current_thread_as_daemon` also automatically detach themselves 122 when finished. The number of currently attached threads may be acquired using 123 `JavaVM::threads_attached` method. (#179, #180) 124- `Executor` — a simple thread attachment manager which helps to safely 125 execute a closure in attached thread context and to automatically free 126 created local references at closure exit. (#186) 127 128### Changed 129- The default JNI API version in `InitArgsBuilder` from V1 to V8. (#178) 130- Extended the lifetimes of `AutoLocal` to make it more flexible. (#190) 131- Default exception type from checked `java.lang.Exception` to unchecked `java.lang.RuntimeException`. 132 It is used implicitly when `JNIEnv#throw` is invoked with exception message: 133 `env.throw("Exception message")`; however, for efficiency reasons, it is recommended 134 to specify the exception type explicitly *and* use `throw_new`: 135 `env.throw_new(exception_type, "Exception message")`. (#194) 136 137### Fixed 138- Native threads attached with `JavaVM::attach_current_thread_as_daemon` now automatically detach 139 themselves on exit, preventing Java Thread leaks. (#179) 140- Local reference leaks in `JList`, `JMap` and `JMapIter`. (#190, #191) 141 142## [0.12.3] 143 144### Added 145- `From<jboolean>` implementation for `JValue` (#173) 146- `Debug` trait for InitArgsBuilder. (#175) 147- `InitArgsBuilder#options` returning the collected JVM options. (#177) 148 149## [0.12.2] 150 151### Changed 152- Updated documentation of GetXArrayRegion methods (#169) 153- Improved ABI compatibility on various platforms (#170) 154 155## [0.12.1] 156 157This release does not bring code changes. 158 159### Changed 160- Updated project documentation. 161 162## [0.12.0] 163 164### Changed 165- `JString`, `JMap` and `JavaStr` and their respective iterators now require an extra lifetime so 166 that they can now work with `&'b JNIEnv<'a>`, where `'a: 'b`. 167 168## [0.11.0] 169 170### Highlights 171This release brings various improvements and fixes, outlined below. The most notable changes are: 172- `null` is no longer represented as an `Err` with error kind `NullPtr` if it is a value of some 173 nullable Java reference (not an indication of an error). Related issues: #136, #148, #163. 174- `unsafe` methods, providing a low-level API similar to JNI, has been marked safe and renamed 175 to have `_unchecked` suffix. Such methods can be used to implement caching of class references 176 and method IDs to improve performance in loops and frequently called Java callbacks. 177 If you have such, check out [the docs][unchecked-docs] and [one of early usages][cache-exonum] 178 of this feature. 179 180[unchecked-docs]: https://docs.rs/jni/0.11.0/jni/struct.JNIEnv.html 181[cache-exonum]: https://github.com/exonum/exonum-java-binding/blob/affa85c026c1870b502725b291822c00f199745d/exonum-java-binding/core/rust/src/utils/jni_cache.rs#L40 182 183### Added 184- Invocation API support on Windows and AppVeyor CI (#149) 185 186### Changed 187- `push_local_frame`, `delete_global_ref` and `release_string_utf_chars` 188no longer check for exceptions as they are 189[safe](https://docs.oracle.com/javase/10/docs/specs/jni/design.html#exception-handling) 190to call if there is a pending exception (#124): 191 - `push_local_frame` will now work in case of pending exceptions — as 192 the spec requires; and fail in case of allocation errors 193 - `delete_global_ref` and `release_string_utf_chars` won't print incorrect 194 log messages 195 196- Rename some macros to better express their intent (see #123): 197 - Rename `jni_call` to `jni_non_null_call` as it checks the return value 198 to be non-null. 199 - Rename `jni_non_null_call` (which may return nulls) to `jni_non_void_call`. 200 201- A lot of public methods of `JNIEnv` have been marked as safe, all unsafe code 202 has been isolated inside internal macros. Methods with `_unsafe` suffixes have 203 been renamed and now have `_unchecked` suffixes (#140) 204 205- `from_str` method of the `JavaType` has been replaced by the `FromStr` 206 implementation 207 208- Implemented Sync for GlobalRef (#102). 209 210- Improvements in macro usage for JNI methods calls (#136): 211 - `call_static_method_unchecked` and `get_static_field_unchecked` methods are 212 allowed to return NULL object 213 - Added checking for pending exception to the `call_static_method_unchecked` 214 method (eliminated WARNING messages in log) 215 216- Further improvements in macro usage for JNI method calls (#150): 217 - The new_global_ref() and new_local_ref() functions are allowed to work with NULL objects according to specification. 218 - Fixed the family of functions new_direct_byte_buffer(), get_direct_buffer_address() and get_direct_buffer_capacity() 219 by adding checking for null and error codes. 220 - Increased tests coverage for JNIEnv functions. 221 222- Implemented Clone for JNIEnv (#147). 223 224- The get_superclass(), get_field_unchecked() and get_object_array_element() are allowed to return NULL object according 225 to the specification (#163). 226 227### Fixed 228- The issue with early detaching of a thread by nested AttachGuard. (#139) 229 230## [0.10.2] 231 232### Added 233- `JavaVM#get_java_vm_pointer` to retrieve a JavaVM pointer (#98) 234- This changelog and other project documents (#106) 235 236### Changed 237- The project is moved to an organization (#104) 238- Updated versions of dependencies (#105) 239- Improved project documents (#107) 240 241### Fixed 242- Crate type of a shared library with native methods 243 must be `cdylib` (#100) 244 245## [0.10.1] 246- No changes has been made to the Changelog until this release. 247 248[Unreleased]: https://github.com/jni-rs/jni-rs/compare/v0.20.0...HEAD 249[0.20.0]: https://github.com/jni-rs/jni-rs/compare/v0.19.0...v0.20.0 250[0.19.0]: https://github.com/jni-rs/jni-rs/compare/v0.18.0...v0.19.0 251[0.18.0]: https://github.com/jni-rs/jni-rs/compare/v0.17.0...v0.18.0 252[0.17.0]: https://github.com/jni-rs/jni-rs/compare/v0.16.0...v0.17.0 253[0.16.0]: https://github.com/jni-rs/jni-rs/compare/v0.15.0...v0.16.0 254[0.15.0]: https://github.com/jni-rs/jni-rs/compare/v0.14.0...v0.15.0 255[0.14.0]: https://github.com/jni-rs/jni-rs/compare/v0.13.1...v0.14.0 256[0.13.1]: https://github.com/jni-rs/jni-rs/compare/v0.13.0...v0.13.1 257[0.13.0]: https://github.com/jni-rs/jni-rs/compare/v0.12.3...v0.13.0 258[0.12.3]: https://github.com/jni-rs/jni-rs/compare/v0.12.2...v0.12.3 259[0.12.2]: https://github.com/jni-rs/jni-rs/compare/v0.12.1...v0.12.2 260[0.12.1]: https://github.com/jni-rs/jni-rs/compare/v0.12.0...v0.12.1 261[0.12.0]: https://github.com/jni-rs/jni-rs/compare/v0.11.0...v0.12.0 262[0.11.0]: https://github.com/jni-rs/jni-rs/compare/v0.10.2...v0.11.0 263[0.10.2]: https://github.com/jni-rs/jni-rs/compare/v0.10.1...v0.10.2 264[0.10.1]: https://github.com/jni-rs/jni-rs/compare/v0.1...v0.10.1 265