diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc index 5518a96017c5c7..bd925d16328d64 100644 --- a/src/main/native/unix_jni.cc +++ b/src/main/native/unix_jni.cc @@ -1015,7 +1015,11 @@ static jbyteArray getxattr_common(JNIEnv *env, } } else { result = env->NewByteArray(size); - env->SetByteArrayRegion(result, 0, size, value); + // Result may be NULL if allocation failed. In that case, we'll return the + // NULL and an OOME will be thrown when we are back in Java. + if (result != NULL) { + env->SetByteArrayRegion(result, 0, size, value); + } } ReleaseStringLatin1Chars(path_chars); ReleaseStringLatin1Chars(name_chars);