am 7d8220a4: Merge change 5286 into donut

Merge commit '7d8220a4d0193b85efd7d289cbff3617f56ef0a9'

* commit '7d8220a4d0193b85efd7d289cbff3617f56ef0a9':
  Check for failure in GetDirectBufferAddress.
diff --git a/vm/Jni.c b/vm/Jni.c
index 10b017c..831a349 100644
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -2768,6 +2768,10 @@
     jmethodID toLongMethod;
     void* result = NULL;
 
+    /*
+     * Start by determining if the object supports the DirectBuffer
+     * interfaces.  Note this does not guarantee that it's a direct buffer.
+     */
     tempClass = (*env)->FindClass(env, 
             "org/apache/harmony/nio/internal/DirectBuffer");
     if(!tempClass)
@@ -2786,6 +2790,20 @@
         goto bail;
     }
     platformAddr = (*env)->CallObjectMethod(env, buf, tempMethod);
+
+    /*
+     * If this isn't a direct buffer, platformAddr will be NULL and/or an
+     * exception will have been thrown.
+     */
+    if ((*env)->ExceptionCheck(env)) {
+        (*env)->ExceptionClear(env);
+        platformAddr = NULL;
+    }
+    if (platformAddr == NULL) {
+        LOGV("Got request for address of non-direct buffer\n");
+        goto bail;
+    }
+
     platformAddrClass = (*env)->FindClass (env, 
             "org/apache/harmony/luni/platform/PlatformAddress");
     if(!platformAddrClass)