Merge "JNI: NewDirectByteBuffer should allow 0 length buffers."
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc
index a84e18a..09c48b1 100644
--- a/runtime/check_jni.cc
+++ b/runtime/check_jni.cc
@@ -1754,8 +1754,8 @@
     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 9194da5..d53cf5e 100644
--- a/test/JniTest/JniTest.java
+++ b/test/JniTest/JniTest.java
@@ -23,6 +23,7 @@
         testFindFieldOnAttachedNativeThread();
         testCallStaticVoidMethodOnSubClass();
         testGetMirandaMethod();
+        testZeroLengthByteBuffers();
     }
 
     private static native void testFindClassOnAttachedNativeThread();
@@ -67,6 +68,8 @@
         }
     }
 
+    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 d15e180..33af94b 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 @@
   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);
+}