diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 0a8a1bcf36..065e8a45ff 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -143,9 +143,15 @@ throwSocketException(JNIEnv* e, const char* s) void throwSocketException(JNIEnv* e, jbyteArray a) { - jbyte* s = static_cast(e->GetPrimitiveArrayCritical(a, 0)); - throwSocketException(e, reinterpret_cast(s)); - e->ReleasePrimitiveArrayCritical(a, s, 0); + size_t length = e->GetArrayLength(a); + uint8_t* buf = static_cast(allocate(e, length)); + if (buf) { + e->GetByteArrayRegion(a, 0, length, reinterpret_cast(buf)); + throwSocketException(e, reinterpret_cast(buf)); + free(buf); + } else { + return; + } } void