8130344: assert(handle != __null) failed: JNI handle should not be null' in jni_GetLongArrayElements
authorjfdenise
Mon, 13 Jul 2015 14:05:17 +0100
changeset 31810 3b32c5ff56e4
parent 31678 7a5da9274448
child 31811 ce4e93d5369d
8130344: assert(handle != __null) failed: JNI handle should not be null' in jni_GetLongArrayElements Summary: Check JNI NewArray for NULL value Reviewed-by: lfoltan, alanb, dholmes
jdk/src/java.base/share/classes/jdk/internal/jimage/ImageNativeSubstrate.java
jdk/src/java.base/share/native/libjava/Image.c
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageNativeSubstrate.java	Thu Jul 09 22:46:18 2015 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageNativeSubstrate.java	Mon Jul 13 14:05:17 2015 +0100
@@ -112,7 +112,12 @@
 
     @Override
     public byte[] getStringBytes(int offset) {
-        return getStringBytes(id, offset);
+        byte[] ret = getStringBytes(id, offset);
+        if (ret == null) {
+            throw new OutOfMemoryError("Error accessing array at offset "
+                    + offset);
+        }
+        return ret;
     }
 
     @Override
--- a/jdk/src/java.base/share/native/libjava/Image.c	Thu Jul 09 22:46:18 2015 -0700
+++ b/jdk/src/java.base/share/native/libjava/Image.c	Mon Jul 13 14:05:17 2015 +0100
@@ -104,6 +104,9 @@
     size = strlen(data);
     // Allocate byte array.
     byteArray = (*env)->NewByteArray(env, (jsize) size);
+    if (byteArray == NULL) {
+        return NULL;
+    }
     // Get array base address.
     rawBytes = (*env)->GetByteArrayElements(env, byteArray, NULL);
     // Copy bytes from image string table.
@@ -122,6 +125,9 @@
     jlong* ret;
 
     attributes = (*env)->NewLongArray(env, JVM_ImageGetAttributesCount(env));
+    if (attributes == NULL) {
+        return NULL;
+    }
     // Get base address for jlong array.
     rawAttributes = (*env)->GetLongArrayElements(env, attributes, NULL);
     ret = JVM_ImageGetAttributes(env, rawAttributes, id, offset);
@@ -143,6 +149,9 @@
 
     count = JVM_ImageGetAttributesCount(env);
     attributes = (*env)->NewLongArray(env, JVM_ImageGetAttributesCount(env));
+    if (attributes == NULL) {
+        return NULL;
+    }
     // Get base address for jlong array.
     rawAttributes = (*env)->GetLongArrayElements(env, attributes, NULL);
     size = (*env)->GetArrayLength(env, utf8);
@@ -165,6 +174,9 @@
 
     length = JVM_ImageAttributeOffsetsLength(env, id);
     offsets = (*env)->NewIntArray(env, length);
+    if (offsets == NULL) {
+        return NULL;
+    }
     // Get base address of result.
     rawOffsets = (*env)->GetIntArrayElements(env, offsets, NULL);
     ret = JVM_ImageAttributeOffsets(env, rawOffsets, length, id);