diff options
| -rw-r--r-- | runtime/check_jni.cc | 4 | ||||
| -rw-r--r-- | test/JniTest/JniTest.java | 3 | ||||
| -rw-r--r-- | test/JniTest/jni_test.cc | 12 |
3 files changed, 17 insertions, 2 deletions
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc index a84e18acc8..09c48b1220 100644 --- a/runtime/check_jni.cc +++ b/runtime/check_jni.cc @@ -1754,8 +1754,8 @@ PRIMITIVE_ARRAY_FUNCTIONS(jdouble, Double, 'D'); if (address == NULL) { JniAbortF(__FUNCTION__, "non-nullable address is NULL"); } - if (capacity <= 0) { - JniAbortF(__FUNCTION__, "capacity must be greater than 0: %lld", capacity); + if (capacity < 0) { + JniAbortF(__FUNCTION__, "capacity must be non negative: %lld", capacity); } return CHECK_JNI_EXIT("L", baseEnv(env)->NewDirectByteBuffer(env, address, capacity)); } diff --git a/test/JniTest/JniTest.java b/test/JniTest/JniTest.java index 9194da581f..d53cf5e564 100644 --- a/test/JniTest/JniTest.java +++ b/test/JniTest/JniTest.java @@ -23,6 +23,7 @@ class JniTest { testFindFieldOnAttachedNativeThread(); testCallStaticVoidMethodOnSubClass(); testGetMirandaMethod(); + testZeroLengthByteBuffers(); } private static native void testFindClassOnAttachedNativeThread(); @@ -67,6 +68,8 @@ class JniTest { } } + private static native void testZeroLengthByteBuffers(); + private static abstract class testGetMirandaMethod_MirandaAbstract implements testGetMirandaMethod_MirandaInterface { public boolean inAbstract() { return true; diff --git a/test/JniTest/jni_test.cc b/test/JniTest/jni_test.cc index d15e180c02..33af94b2ab 100644 --- a/test/JniTest/jni_test.cc +++ b/test/JniTest/jni_test.cc @@ -17,6 +17,7 @@ #include <assert.h> #include <stdio.h> #include <pthread.h> +#include <vector> #include "jni.h" @@ -125,3 +126,14 @@ extern "C" JNIEXPORT jobject JNICALL Java_JniTest_testGetMirandaMethodNative(JNI assert(miranda_method != NULL); return env->ToReflectedMethod(abstract_class, miranda_method, JNI_FALSE); } + +// https://code.google.com/p/android/issues/detail?id=63055 +extern "C" void JNICALL Java_JniTest_testZeroLengthByteBuffers(JNIEnv* env, jclass) { + std::vector<uint8_t> buffer(1); + jobject byte_buffer = env->NewDirectByteBuffer(&buffer[0], 0); + assert(byte_buffer != NULL); + assert(!env->ExceptionCheck()); + + assert(env->GetDirectBufferAddress(byte_buffer) == &buffer[0]); + assert(env->GetDirectBufferCapacity(byte_buffer) == 0); +} |