Fix NULL values for default constructors in JNI

Description

Because empty Java constructors implicitly set NULL values for their fields as default values, on the JNI boundary this could result in NullPointerException when we try to convert a Java object into a Rust object. This should be fixed either by ignoring NPE in this case or by implementing proper default constructors assigning default values to the object fields.

Environment

None

Gliffy Diagrams

Activity

Nikita Baksalyar April 9, 2018 at 1:42 PM

Paused - this task is implemented; waiting for https://github.com/prevoty/jni-rs/pull/90 to be merged.

Nikita Baksalyar April 5, 2018 at 8:36 AM

Updated story points to 8: while the merged PR fixes this issue partially, we need to change the Java code generator a little bit. Ignoring NPE}}s is not feasible because the {{Default trait is not implemented for many types, including the [u8; 32] array type that we use extensively for XorNames, encryption keys, etc. This can be solved by using mem::zeroed to initialise default values with zeroed memory, but I feel this might be a hack and a fragile way of doing this.

Instead, it's better to initialise the object values on the Java side. And to implement this properly, we might need to do a refactoring of the bindgen internals to derive correct Java types: now they are stored as strings and currently it's hard to derive a proper constructor type we should call. Instead, the proposal is to store types as enums variants which can be found in the jni-rs crate that we already use.

Done

Details

Assignee

Reporter

Labels

Start date

End date

Story Points

Components

Priority

Created April 4, 2018 at 11:09 AM
Updated September 11, 2018 at 9:02 AM
Resolved April 26, 2018 at 1:04 PM