jni: tolerate nil byte arrays in GetByteArrayElements

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/5/head
Elias Naur 4 years ago
parent de6c243bae
commit 1c61cc0702

@ -154,6 +154,9 @@ func CallIntMethod(e Env, obj Object, method MethodID, args ...Value) (int32, er
// GetByteArrayElements returns the contents of the array. // GetByteArrayElements returns the contents of the array.
func GetByteArrayElements(e Env, jarr ByteArray) []byte { func GetByteArrayElements(e Env, jarr ByteArray) []byte {
if jarr == 0 {
return nil
}
size := C._jni_GetArrayLength(e.env, C.jarray(jarr)) size := C._jni_GetArrayLength(e.env, C.jarray(jarr))
elems := C._jni_GetByteArrayElements(e.env, C.jbyteArray(jarr)) elems := C._jni_GetByteArrayElements(e.env, C.jbyteArray(jarr))
defer C._jni_ReleaseByteArrayElements(e.env, C.jbyteArray(jarr), elems, 0) defer C._jni_ReleaseByteArrayElements(e.env, C.jbyteArray(jarr), elems, 0)

Loading…
Cancel
Save