8175516: JNI exception pending in jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c:97
authorkvn
Mon, 27 Feb 2017 15:59:22 -0800
changeset 44086 9a5b97523f70
parent 44085 68b17649266b
child 44087 deab1e2f0ebf
8175516: JNI exception pending in jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c:97 Summary: add missing NULL checks Reviewed-by: iveresov
hotspot/src/jdk.aot/unix/native/libjelfshim/jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c
--- a/hotspot/src/jdk.aot/unix/native/libjelfshim/jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c	Mon Feb 27 18:24:19 2017 +0100
+++ b/hotspot/src/jdk.aot/unix/native/libjelfshim/jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c	Mon Feb 27 15:59:22 2017 -0800
@@ -70,18 +70,17 @@
  */
 
 static jlong getNativeAddress(JNIEnv* env, jobject ptrObj) {
-   jclass ptrClass;
-   jfieldID fidNumber;
    jlong nativeAddress = -1;
-    assert (ptrObj != NULL);
+   assert (ptrObj != NULL);
    // Get a reference to ptr object's class
-   ptrClass = (*env)->GetObjectClass(env, ptrObj);
-
-   // Get the Field ID of the instance variables "address"
-   fidNumber = (*env)->GetFieldID(env, ptrClass, "address", "J");
-   if (fidNumber != NULL) {
-       // Get the long given the Field ID
-       nativeAddress = (*env)->GetLongField(env, ptrObj, fidNumber);
+   jclass ptrClass = (*env)->GetObjectClass(env, ptrObj);
+   if (ptrClass != NULL) {
+       // Get the Field ID of the instance variables "address"
+       jfieldID fidNumber = (*env)->GetFieldID(env, ptrClass, "address", "J");
+       if (fidNumber != NULL) {
+           // Get the long given the Field ID
+           nativeAddress = (*env)->GetLongField(env, ptrObj, fidNumber);
+       }
    }
    // fprintf(stderr, "Native address : %lx\n", nativeAddress);
    return nativeAddress;
@@ -91,10 +90,15 @@
  * Box the nativeAddress as a Pointer object.
  */
 static jobject makePointerObject(JNIEnv* env, jlong nativeAddr) {
+   jobject retObj = NULL;
    jclass ptrClass = (*env)->FindClass(env, "jdk/tools/jaotc/jnilibelf/Pointer");
-   // Call back constructor to allocate a Pointer object, with an int argument
-   jmethodID constructorId = (*env)->GetMethodID(env, ptrClass, "<init>", "(J)V");
-   jobject retObj = (*env)->NewObject(env, ptrClass, constructorId, nativeAddr);
+   if (ptrClass != NULL) {
+       // Call back constructor to allocate a Pointer object, with an int argument
+       jmethodID constructorId = (*env)->GetMethodID(env, ptrClass, "<init>", "(J)V");
+       if (constructorId != NULL) {
+           retObj = (*env)->NewObject(env, ptrClass, constructorId, nativeAddr);
+       }
+   }
    return retObj;
 }