8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
authoralanb
Tue, 04 Feb 2014 12:05:13 +0000
changeset 22641 e47f8892133e
parent 22640 58db7b59eaf6
child 22642 68427b2d9c2b
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues 8033371: jdk/src/solaris/native/java/lang/ProcessEnvironment.c environ doesn't check for JNI pending exceptions 8030116: (process) Check Parfait warnings in src/solaris/native/java/lang/* 8028769: Check src/share/native/java/lang/*.c for cases when JNI calls are used with pending warnings Reviewed-by: chegar
jdk/src/share/native/java/io/io_util.c
jdk/src/share/native/java/lang/ClassLoader.c
jdk/src/share/native/java/lang/System.c
jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
jdk/src/solaris/native/java/lang/UNIXProcess_md.c
jdk/src/solaris/native/java/lang/java_props_md.c
jdk/src/windows/native/java/lang/ProcessEnvironment_md.c
--- a/jdk/src/share/native/java/io/io_util.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/share/native/java/io/io_util.c	Tue Feb 04 12:05:13 2014 +0000
@@ -216,6 +216,7 @@
 #else
         why = JNU_NewStringPlatform(env, buf);
 #endif
+        CHECK_NULL(why);
     }
     x = JNU_NewObjectByName(env,
                             "java/io/FileNotFoundException",
--- a/jdk/src/share/native/java/lang/ClassLoader.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/share/native/java/lang/ClassLoader.c	Tue Feb 04 12:05:13 2014 +0000
@@ -132,7 +132,6 @@
     if (name != NULL) {
         utfName = getUTF(env, name, buf, sizeof(buf));
         if (utfName == NULL) {
-            JNU_ThrowOutOfMemoryError(env, NULL);
             goto free_body;
         }
         VerifyFixClassname(utfName);
@@ -143,7 +142,6 @@
     if (source != NULL) {
         utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
         if (utfSource == NULL) {
-            JNU_ThrowOutOfMemoryError(env, NULL);
             goto free_utfName;
         }
     } else {
@@ -519,7 +517,6 @@
     procHandle = getProcessHandle();
     cname = JNU_GetStringPlatformChars(env, name, 0);
     if (cname == NULL) {
-        JNU_ThrowOutOfMemoryError(env, NULL);
         return NULL;
     }
     // Copy name Skipping PREFIX
--- a/jdk/src/share/native/java/lang/System.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/share/native/java/lang/System.c	Tue Feb 04 12:05:13 2014 +0000
@@ -56,44 +56,56 @@
     return JVM_IHashCode(env, x);
 }
 
-#define PUTPROP(props, key, val) \
-    if (1) { \
-        jstring jkey = (*env)->NewStringUTF(env, key); \
-        jstring jval = (*env)->NewStringUTF(env, val); \
-        jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
-        if ((*env)->ExceptionOccurred(env)) return NULL; \
-        (*env)->DeleteLocalRef(env, jkey); \
-        (*env)->DeleteLocalRef(env, jval); \
-        (*env)->DeleteLocalRef(env, r); \
+#define PUTPROP(props, key, val)                                     \
+    if (1) {                                                         \
+        jstring jkey, jval;                                          \
+        jobject r;                                                   \
+        jkey = (*env)->NewStringUTF(env, key);                       \
+        if (jkey == NULL) return NULL;                               \
+        jval = (*env)->NewStringUTF(env, val);                       \
+        if (jval == NULL) return NULL;                               \
+        r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
+        if ((*env)->ExceptionOccurred(env)) return NULL;             \
+        (*env)->DeleteLocalRef(env, jkey);                           \
+        (*env)->DeleteLocalRef(env, jval);                           \
+        (*env)->DeleteLocalRef(env, r);                              \
     } else ((void) 0)
 
 /*  "key" is a char type string with only ASCII character in it.
     "val" is a nchar (typedefed in java_props.h) type string  */
 
-#define PUTPROP_ForPlatformNString(props, key, val) \
-    if (1) { \
-        jstring jkey = (*env)->NewStringUTF(env, key);  \
-        jstring jval = GetStringPlatform(env, val); \
-        jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
-        if ((*env)->ExceptionOccurred(env)) return NULL; \
-        (*env)->DeleteLocalRef(env, jkey); \
-        (*env)->DeleteLocalRef(env, jval); \
-        (*env)->DeleteLocalRef(env, r); \
+#define PUTPROP_ForPlatformNString(props, key, val)                  \
+    if (1) {                                                         \
+        jstring jkey, jval;                                          \
+        jobject r;                                                   \
+        jkey = (*env)->NewStringUTF(env, key);                       \
+        if (jkey == NULL) return NULL;                               \
+        jval = GetStringPlatform(env, val);                          \
+        if (jval == NULL) return NULL;                               \
+        r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
+        if ((*env)->ExceptionOccurred(env)) return NULL;             \
+        (*env)->DeleteLocalRef(env, jkey);                           \
+        (*env)->DeleteLocalRef(env, jval);                           \
+        (*env)->DeleteLocalRef(env, r);                              \
     } else ((void) 0)
-#define REMOVEPROP(props, key) \
-    if (1) { \
-        jstring jkey = JNU_NewStringPlatform(env, key); \
-        jobject r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
-        if ((*env)->ExceptionOccurred(env)) return NULL; \
-        (*env)->DeleteLocalRef(env, jkey); \
-        (*env)->DeleteLocalRef(env, r); \
+#define REMOVEPROP(props, key)                                    \
+    if (1) {                                                      \
+        jstring jkey;                                             \
+        jobject r;                                                \
+        jkey = JNU_NewStringPlatform(env, key);                   \
+        if (jkey == NULL) return NULL;                            \
+        r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
+        if ((*env)->ExceptionOccurred(env)) return NULL;          \
+        (*env)->DeleteLocalRef(env, jkey);                        \
+        (*env)->DeleteLocalRef(env, r);                           \
     } else ((void) 0)
-#define GETPROP(props, key, jret) \
-    if (1) { \
-        jstring jkey = JNU_NewStringPlatform(env, key); \
+#define GETPROP(props, key, jret)                                     \
+    if (1) {                                                          \
+        jstring jkey = JNU_NewStringPlatform(env, key);               \
+        if (jkey == NULL) return NULL;                                \
         jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
-        if ((*env)->ExceptionOccurred(env)) return NULL; \
-        (*env)->DeleteLocalRef(env, jkey); \
+        if ((*env)->ExceptionOccurred(env)) return NULL;              \
+        (*env)->DeleteLocalRef(env, jkey);                            \
     } else ((void) 0)
 
 #ifndef VENDOR /* Third party may overwrite this. */
@@ -169,23 +181,31 @@
 Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
 {
     char buf[128];
-    java_props_t *sprops = GetJavaProperties(env);
-    jmethodID putID = (*env)->GetMethodID(env,
-                                          (*env)->GetObjectClass(env, props),
-                                          "put",
-            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    jmethodID removeID = (*env)->GetMethodID(env,
-                                          (*env)->GetObjectClass(env, props),
-                                          "remove",
-            "(Ljava/lang/Object;)Ljava/lang/Object;");
-    jmethodID getPropID = (*env)->GetMethodID(env,
-                                          (*env)->GetObjectClass(env, props),
-                                          "getProperty",
-            "(Ljava/lang/String;)Ljava/lang/String;");
+    java_props_t *sprops;
+    jmethodID putID, removeID, getPropID;
     jobject ret = NULL;
     jstring jVMVal = NULL;
 
-    if (sprops == NULL || putID == NULL ) return NULL;
+    sprops = GetJavaProperties(env);
+    CHECK_NULL_RETURN(sprops, NULL);
+
+    putID = (*env)->GetMethodID(env,
+                                (*env)->GetObjectClass(env, props),
+                                "put",
+            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+    CHECK_NULL_RETURN(putID, NULL);
+
+    removeID = (*env)->GetMethodID(env,
+                                   (*env)->GetObjectClass(env, props),
+                                   "remove",
+            "(Ljava/lang/Object;)Ljava/lang/Object;");
+    CHECK_NULL_RETURN(removeID, NULL);
+
+    getPropID = (*env)->GetMethodID(env,
+                                    (*env)->GetObjectClass(env, props),
+                                    "getProperty",
+            "(Ljava/lang/String;)Ljava/lang/String;");
+    CHECK_NULL_RETURN(getPropID, NULL);
 
     PUTPROP(props, "java.specification.version",
             JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
@@ -382,6 +402,7 @@
     GETPROP(props, "sun.locale.formatasdefault", jVMVal);
     if (jVMVal) {
         const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0);
+        CHECK_NULL_RETURN(val, NULL);
         fmtdefault = !strcmp(val, "true");
         (*env)->ReleaseStringUTFChars(env, jVMVal, val);
         (*env)->DeleteLocalRef(env, jVMVal);
--- a/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c	Tue Feb 04 12:05:13 2014 +0000
@@ -53,6 +53,7 @@
     jsize i, j;
     jobjectArray result;
     jclass byteArrCls = (*env)->FindClass(env, "[B");
+    CHECK_NULL_RETURN(byteArrCls, NULL);
 
     for (i = 0; environ[i]; i++) {
         /* Ignore corrupted environment variables */
@@ -61,7 +62,7 @@
     }
 
     result = (*env)->NewObjectArray(env, 2*count, byteArrCls, 0);
-    if (result == NULL) return NULL;
+    CHECK_NULL_RETURN(result, NULL);
 
     for (i = 0, j = 0; environ[i]; i++) {
         const char * varEnd = strchr(environ[i], '=');
@@ -72,9 +73,9 @@
             jsize varLength = varEnd - environ[i];
             jsize valLength = strlen(valBeg);
             var = (*env)->NewByteArray(env, varLength);
-            if (var == NULL) return NULL;
+            CHECK_NULL_RETURN(var, NULL);
             val = (*env)->NewByteArray(env, valLength);
-            if (val == NULL) return NULL;
+            CHECK_NULL_RETURN(val, NULL);
             (*env)->SetByteArrayRegion(env, var, 0, varLength,
                                        (jbyte*) environ[i]);
             (*env)->SetByteArrayRegion(env, val, 0, valLength,
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c	Tue Feb 04 12:05:13 2014 +0000
@@ -206,6 +206,7 @@
 Java_java_lang_UNIXProcess_init(JNIEnv *env, jclass clazz)
 {
     parentPathv = effectivePathv(env);
+    CHECK_NULL(parentPathv);
     setSIGCHLDHandler(env);
 }
 
--- a/jdk/src/solaris/native/java/lang/java_props_md.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/solaris/native/java/lang/java_props_md.c	Tue Feb 04 12:05:13 2014 +0000
@@ -546,6 +546,9 @@
     sprops.display_country = sprops.country;
     sprops.display_variant = sprops.variant;
 
+    /* ParseLocale failed with OOME */
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
+
 #ifdef MACOSX
     sprops.sun_jnu_encoding = "UTF-8";
 #else
--- a/jdk/src/windows/native/java/lang/ProcessEnvironment_md.c	Tue Feb 04 11:31:27 2014 +0000
+++ b/jdk/src/windows/native/java/lang/ProcessEnvironment_md.c	Tue Feb 04 12:05:13 2014 +0000
@@ -32,10 +32,15 @@
 environmentBlock9x(JNIEnv *env)
 {
     int i;
-    jmethodID String_init_ID =
+    jmethodID String_init_ID;
+    jbyteArray bytes;
+    jbyte *blockA;
+
+    String_init_ID =
         (*env)->GetMethodID(env, JNU_ClassString(env), "<init>", "([B)V");
-    jbyteArray bytes;
-    jbyte *blockA = (jbyte *) GetEnvironmentStringsA();
+    CHECK_NULL_RETURN(String_init_ID, NULL);
+
+    blockA = (jbyte *) GetEnvironmentStringsA();
     if (blockA == NULL) {
         /* Both GetEnvironmentStringsW and GetEnvironmentStringsA
          * failed.  Out of memory is our best guess.  */