changeset 9224:01b83dcdcc36

8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons 8032668: Check jdk/src/solaris/native/java/io for pending JNI exception issues Reviewed-by: chegar, simonis
author alanb
date Mon, 03 Feb 2014 14:00:43 +0000
parents 5f2230367b68
children 79745e1148c0
files src/aix/classes/sun/nio/fs/AixNativeDispatcher.java src/aix/native/sun/nio/fs/AixNativeDispatcher.c src/solaris/native/java/io/UnixFileSystem_md.c src/solaris/native/sun/nio/ch/DatagramChannelImpl.c src/solaris/native/sun/nio/ch/FileKey.c src/solaris/native/sun/nio/ch/IOUtil.c src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c src/solaris/native/sun/nio/ch/sctp/SctpNet.c src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c src/windows/native/java/io/FileDescriptor_md.c src/windows/native/java/io/WinNTFileSystem_md.c src/windows/native/sun/nio/ch/DatagramChannelImpl.c src/windows/native/sun/nio/ch/FileKey.c src/windows/native/sun/nio/ch/IOUtil.c src/windows/native/sun/nio/ch/Iocp.c src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c src/windows/native/sun/nio/ch/SocketChannelImpl.c src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c
diffstat 22 files changed, 198 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/aix/classes/sun/nio/fs/AixNativeDispatcher.java	Mon Feb 03 14:00:43 2014 +0000
@@ -43,7 +43,7 @@
     static native UnixMountEntry[] getmntctl() throws UnixException;
 
     // initialize
-    private static native int init();
+    private static native void init();
 
     static {
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
--- a/src/aix/native/sun/nio/fs/AixNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/aix/native/sun/nio/fs/AixNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -56,23 +56,26 @@
 /**
  * Initialization
  */
-JNIEXPORT jint JNICALL
+JNIEXPORT void JNICALL
 Java_sun_nio_fs_AixNativeDispatcher_init(JNIEnv* env, jclass this)
 {
-    jint flags = 0;
     jclass clazz;
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
-    if (clazz == NULL) {
-        return 0;
+    CHECK_NULL(clazz);
+    entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    CHECK_NULL(entry_name);
+    entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    CHECK_NULL(entry_dir);
+    entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    CHECK_NULL(entry_fstype);
+    entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    CHECK_NULL(entry_options);
+    entry_cls = (*env)->NewGlobalRef(env, clazz);
+    if (entry_cls == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
     }
-    entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
-    entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
-    entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
-    entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
-    entry_cls = (*env)->NewGlobalRef(env, clazz);
-
-    return 0;
 }
 
 /**
--- a/src/solaris/native/java/io/UnixFileSystem_md.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/java/io/UnixFileSystem_md.c	Mon Feb 03 14:00:43 2014 +0000
@@ -283,6 +283,10 @@
     struct dirent64 *result;
     int len, maxlen;
     jobjectArray rv, old;
+    jclass str_class;
+
+    str_class = JNU_ClassString(env);
+    CHECK_NULL_RETURN(str_class, NULL);
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
         dir = opendir(path);
@@ -299,7 +303,7 @@
     /* Allocate an initial String array */
     len = 0;
     maxlen = 16;
-    rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL);
+    rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
     if (rv == NULL) goto error;
 
     /* Scan the directory */
@@ -309,8 +313,7 @@
             continue;
         if (len == maxlen) {
             old = rv;
-            rv = (*env)->NewObjectArray(env, maxlen <<= 1,
-                                        JNU_ClassString(env), NULL);
+            rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
             if (rv == NULL) goto error;
             if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
             (*env)->DeleteLocalRef(env, old);
@@ -329,7 +332,7 @@
 
     /* Copy the final results into an appropriately-sized array */
     old = rv;
-    rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL);
+    rv = (*env)->NewObjectArray(env, len, str_class, NULL);
     if (rv == NULL) {
         return NULL;
     }
--- a/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -56,18 +56,28 @@
 Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz)
 {
     clazz = (*env)->FindClass(env, "java/net/InetSocketAddress");
+    CHECK_NULL(clazz);
     isa_class = (*env)->NewGlobalRef(env, clazz);
+    if (isa_class == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
     isa_ctorID = (*env)->GetMethodID(env, clazz, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
+    CHECK_NULL(isa_ctorID);
 
     clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl");
+    CHECK_NULL(clazz);
     dci_senderID = (*env)->GetFieldID(env, clazz, "sender",
                                       "Ljava/net/SocketAddress;");
+    CHECK_NULL(dci_senderID);
     dci_senderAddrID = (*env)->GetFieldID(env, clazz,
                                           "cachedSenderInetAddress",
                                           "Ljava/net/InetAddress;");
+    CHECK_NULL(dci_senderAddrID);
     dci_senderPortID = (*env)->GetFieldID(env, clazz,
                                           "cachedSenderPort", "I");
+    CHECK_NULL(dci_senderPortID);
 }
 
 JNIEXPORT void JNICALL
@@ -121,7 +131,7 @@
          * but that is acceptable.
          */
         if (rv < 0 && errno == EAFNOSUPPORT)
-                rv = errno = 0;
+            rv = errno = 0;
 #endif
     }
 #endif
@@ -192,17 +202,11 @@
     if (senderAddr == NULL) {
         jobject isa = NULL;
         int port;
-        jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa,
-                                               &port);
-
+        jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
         if (ia != NULL) {
             isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
         }
-
-        if (isa == NULL) {
-            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
-            return IOS_THROWN;
-        }
+        CHECK_NULL_RETURN(isa, IOS_THROWN);
 
         (*env)->SetObjectField(env, this, dci_senderAddrID, ia);
         (*env)->SetIntField(env, this, dci_senderPortID,
--- a/src/solaris/native/sun/nio/ch/FileKey.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/FileKey.c	Mon Feb 03 14:00:43 2014 +0000
@@ -43,8 +43,8 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz)
 {
-    key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J");
-    key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J");
+    CHECK_NULL(key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J"));
+    CHECK_NULL(key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J"));
 }
 
 
--- a/src/solaris/native/sun/nio/ch/IOUtil.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/IOUtil.c	Mon Feb 03 14:00:43 2014 +0000
@@ -42,8 +42,8 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
 {
-    clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
-    fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
+    CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
+    CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
 }
 
 JNIEXPORT jboolean JNICALL
--- a/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -57,12 +57,20 @@
     jclass cls;
 
     cls = (*env)->FindClass(env, "java/io/FileDescriptor");
+    CHECK_NULL(cls);
     fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I");
+    CHECK_NULL(fd_fdID);
 
     cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
+    CHECK_NULL(cls);
     isa_class = (*env)->NewGlobalRef(env, cls);
+    if (isa_class == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
     isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
+    CHECK_NULL(isa_ctorID);
 }
 
 JNIEXPORT jint JNICALL
@@ -79,6 +87,10 @@
     jint remote_port;
 
     NET_AllocSockaddr(&sa, &alloc_len);
+    if (sa == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return IOS_THROWN;
+    }
 
     /*
      * accept connection but ignore ECONNABORTED indicating that
@@ -110,8 +122,9 @@
     (*env)->SetIntField(env, newfdo, fd_fdID, newfd);
     remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
     free((void *)sa);
-    isa = (*env)->NewObject(env, isa_class, isa_ctorID,
-                            remote_ia, remote_port);
+    CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
+    isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
+    CHECK_NULL_RETURN(isa, IOS_THROWN);
     (*env)->SetObjectArrayElement(env, isaa, 0, isa);
     return 1;
 }
--- a/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/sctp/SctpChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -214,6 +214,7 @@
 
     /* retrieved address from sockaddr */
     isaObj = SockAddrToInetSocketAddress(env, sap);
+    CHECK_NULL(isaObj);
 
     /* data retrieved from sff_data */
     if (dataLength > 0) {
@@ -338,6 +339,7 @@
     }
 
     addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr);
+    CHECK_NULL(addressObj);
 
     /* create PeerAddressChanged */
     resultObj = (*env)->NewObject(env, spc_class, spc_ctrID, spc->spc_assoc_id,
@@ -394,6 +396,7 @@
     }
 
     isa = SockAddrToInetSocketAddress(env, sap);
+    CHECK_NULL(isa);
     getControlData(msg, cdata);
 
     /* create MessageInfoImpl */
@@ -580,4 +583,3 @@
     return Java_sun_nio_ch_SocketChannelImpl_checkConnect(env, this,
                                                           fdo, block, ready);
 }
-
--- a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c	Mon Feb 03 14:00:43 2014 +0000
@@ -382,8 +382,9 @@
         ia = NET_SockaddrToInetAddress(env, sap, &port);
         if (ia != NULL)
             isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
-        if (isa != NULL)
-            (*env)->SetObjectArrayElement(env, isaa, i, isa);
+        if (isa == NULL)
+            break;
+        (*env)->SetObjectArrayElement(env, isaa, i, isa);
 
         if (sap->sa_family == AF_INET)
             addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
@@ -433,8 +434,9 @@
         ia = NET_SockaddrToInetAddress(env, sap, &port);
         if (ia != NULL)
             isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
-        if (isa != NULL)
-            (*env)->SetObjectArrayElement(env, isaa, i, isa);
+        if (isa == NULL)
+            break;
+        (*env)->SetObjectArrayElement(env, isaa, i, isa);
 
         if (sap->sa_family == AF_INET)
             addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
--- a/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/fs/BsdNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -72,13 +72,15 @@
     jclass clazz;
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    CHECK_NULL(entry_name);
     entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    CHECK_NULL(entry_dir);
     entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    CHECK_NULL(entry_fstype);
     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    CHECK_NULL(entry_options);
 }
 
 JNIEXPORT jlong JNICALL
@@ -201,4 +203,3 @@
         free(iter);
     }
 }
-
--- a/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -68,13 +68,15 @@
     my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr");
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
-    if (clazz == NULL)
-        return;
-
+    CHECK_NULL(clazz);
     entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    CHECK_NULL(entry_name);
     entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    CHECK_NULL(entry_dir);
     entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    CHECK_NULL(entry_fstype);
     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    CHECK_NULL(entry_options);
 }
 
 JNIEXPORT jint JNICALL
--- a/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -55,14 +55,17 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
-    if (clazz == NULL)
-        return;
-
+    CHECK_NULL(clazz);
     entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    CHECK_NULL(entry_name);
     entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    CHECK_NULL(entry_dir);
     entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    CHECK_NULL(entry_fstype);
     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    CHECK_NULL(entry_options);
     entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
+    CHECK_NULL(entry_dev);
 }
 
 JNIEXPORT jint JNICALL
--- a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -179,46 +179,64 @@
     jclass clazz;
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes");
-    if (clazz == NULL) {
-        return 0;
-    }
+    CHECK_NULL_RETURN(clazz, 0);
     attrs_st_mode = (*env)->GetFieldID(env, clazz, "st_mode", "I");
+    CHECK_NULL_RETURN(attrs_st_mode, 0);
     attrs_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J");
+    CHECK_NULL_RETURN(attrs_st_ino, 0);
     attrs_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J");
+    CHECK_NULL_RETURN(attrs_st_dev, 0);
     attrs_st_rdev = (*env)->GetFieldID(env, clazz, "st_rdev", "J");
+    CHECK_NULL_RETURN(attrs_st_rdev, 0);
     attrs_st_nlink = (*env)->GetFieldID(env, clazz, "st_nlink", "I");
+    CHECK_NULL_RETURN(attrs_st_nlink, 0);
     attrs_st_uid = (*env)->GetFieldID(env, clazz, "st_uid", "I");
+    CHECK_NULL_RETURN(attrs_st_uid, 0);
     attrs_st_gid = (*env)->GetFieldID(env, clazz, "st_gid", "I");
+    CHECK_NULL_RETURN(attrs_st_gid, 0);
     attrs_st_size = (*env)->GetFieldID(env, clazz, "st_size", "J");
+    CHECK_NULL_RETURN(attrs_st_size, 0);
     attrs_st_atime_sec = (*env)->GetFieldID(env, clazz, "st_atime_sec", "J");
+    CHECK_NULL_RETURN(attrs_st_atime_sec, 0);
     attrs_st_atime_nsec = (*env)->GetFieldID(env, clazz, "st_atime_nsec", "J");
+    CHECK_NULL_RETURN(attrs_st_atime_nsec, 0);
     attrs_st_mtime_sec = (*env)->GetFieldID(env, clazz, "st_mtime_sec", "J");
+    CHECK_NULL_RETURN(attrs_st_mtime_sec, 0);
     attrs_st_mtime_nsec = (*env)->GetFieldID(env, clazz, "st_mtime_nsec", "J");
+    CHECK_NULL_RETURN(attrs_st_mtime_nsec, 0);
     attrs_st_ctime_sec = (*env)->GetFieldID(env, clazz, "st_ctime_sec", "J");
+    CHECK_NULL_RETURN(attrs_st_ctime_sec, 0);
     attrs_st_ctime_nsec = (*env)->GetFieldID(env, clazz, "st_ctime_nsec", "J");
+    CHECK_NULL_RETURN(attrs_st_ctime_nsec, 0);
 
 #ifdef _DARWIN_FEATURE_64_BIT_INODE
     attrs_st_birthtime_sec = (*env)->GetFieldID(env, clazz, "st_birthtime_sec", "J");
+    CHECK_NULL_RETURN(attrs_st_birthtime_sec, 0);
 #endif
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes");
-    if (clazz == NULL) {
-        return 0;
-    }
+    CHECK_NULL_RETURN(clazz, 0);
     attrs_f_frsize = (*env)->GetFieldID(env, clazz, "f_frsize", "J");
+    CHECK_NULL_RETURN(attrs_f_frsize, 0);
     attrs_f_blocks = (*env)->GetFieldID(env, clazz, "f_blocks", "J");
+    CHECK_NULL_RETURN(attrs_f_blocks, 0);
     attrs_f_bfree = (*env)->GetFieldID(env, clazz, "f_bfree", "J");
+    CHECK_NULL_RETURN(attrs_f_bfree, 0);
     attrs_f_bavail = (*env)->GetFieldID(env, clazz, "f_bavail", "J");
+    CHECK_NULL_RETURN(attrs_f_bavail, 0);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
-    if (clazz == NULL) {
-        return 0;
-    }
+    CHECK_NULL_RETURN(clazz, 0);
     entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
+    CHECK_NULL_RETURN(entry_name, 0);
     entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
+    CHECK_NULL_RETURN(entry_dir, 0);
     entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
+    CHECK_NULL_RETURN(entry_fstype, 0);
     entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
+    CHECK_NULL_RETURN(entry_options, 0);
     entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
+    CHECK_NULL_RETURN(entry_dev, 0);
 
     /* system calls that might not be available at run time */
 
--- a/src/windows/native/java/io/FileDescriptor_md.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/java/io/FileDescriptor_md.c	Mon Feb 03 14:00:43 2014 +0000
@@ -48,8 +48,8 @@
 
 JNIEXPORT void JNICALL
 Java_java_io_FileDescriptor_initIDs(JNIEnv *env, jclass fdClass) {
-    IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I");
-    IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J");
+    CHECK_NULL(IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I"));
+    CHECK_NULL(IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J"));
 }
 
 JNIEXPORT jlong JNICALL
--- a/src/windows/native/java/io/WinNTFileSystem_md.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/java/io/WinNTFileSystem_md.c	Mon Feb 03 14:00:43 2014 +0000
@@ -59,10 +59,12 @@
 Java_java_io_WinNTFileSystem_initIDs(JNIEnv *env, jclass cls)
 {
     HMODULE handle;
-    jclass fileClass = (*env)->FindClass(env, "java/io/File");
-    if (!fileClass) return;
-    ids.path =
-             (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;");
+    jclass fileClass;
+
+    fileClass = (*env)->FindClass(env, "java/io/File");
+    CHECK_NULL(fileClass);
+    ids.path = (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;");
+    CHECK_NULL(ids.path);
 
     // GetFinalPathNameByHandle requires Windows Vista or newer
     if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
@@ -243,8 +245,8 @@
     WCHAR canonicalPath[MAX_PATH_LENGTH];
 
     WITH_UNICODE_STRING(env, pathname, path) {
-        /*we estimate the max length of memory needed as
-          "currentDir. length + pathname.length"
+        /* we estimate the max length of memory needed as
+           "currentDir. length + pathname.length"
          */
         int len = (int)wcslen(path);
         len += currentDirLength(path, len);
@@ -256,12 +258,11 @@
                 }
                 free(cp);
             }
-        } else
-        if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
+        } else if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
             rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath));
         }
     } END_UNICODE_STRING(env, path);
-    if (rv == NULL) {
+    if (rv == NULL && !(*env)->ExceptionCheck(env)) {
         JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
     }
     return rv;
@@ -288,15 +289,14 @@
                     }
                     free(cp);
                 }
-            } else
-            if (wcanonicalizeWithPrefix(canonicalPrefix,
-                                        pathWithCanonicalPrefix,
-                                        canonicalPath, MAX_PATH_LENGTH) >= 0) {
+            } else if (wcanonicalizeWithPrefix(canonicalPrefix,
+                                               pathWithCanonicalPrefix,
+                                               canonicalPath, MAX_PATH_LENGTH) >= 0) {
                 rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath));
             }
         } END_UNICODE_STRING(env, pathWithCanonicalPrefix);
     } END_UNICODE_STRING(env, canonicalPrefix);
-    if (rv == NULL) {
+    if (rv == NULL && !(*env)->ExceptionCheck(env)) {
         JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
     }
     return rv;
@@ -616,8 +616,13 @@
     jobjectArray rv, old;
     DWORD fattr;
     jstring name;
+    jclass str_class;
+    WCHAR *pathbuf;
 
-    WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
+    str_class = JNU_ClassString(env);
+    CHECK_NULL_RETURN(str_class, NULL);
+
+    pathbuf = fileToNTPath(env, file, ids.path);
     if (pathbuf == NULL)
         return NULL;
     search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6);
@@ -664,7 +669,7 @@
             return NULL;
         } else {
             // No files found - return an empty array
-            rv = (*env)->NewObjectArray(env, 0, JNU_ClassString(env), NULL);
+            rv = (*env)->NewObjectArray(env, 0, str_class, NULL);
             return rv;
         }
     }
@@ -672,7 +677,7 @@
     /* Allocate an initial String array */
     len = 0;
     maxlen = 16;
-    rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL);
+    rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
     if (rv == NULL) // Couldn't allocate an array
         return NULL;
     /* Scan the directory */
@@ -686,10 +691,8 @@
             return NULL; // error;
         if (len == maxlen) {
             old = rv;
-            rv = (*env)->NewObjectArray(env, maxlen <<= 1,
-                                            JNU_ClassString(env), NULL);
-            if ( rv == NULL
-                         || JNU_CopyObjectArray(env, rv, old, len) < 0)
+            rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
+            if (rv == NULL || JNU_CopyObjectArray(env, rv, old, len) < 0)
                 return NULL; // error
             (*env)->DeleteLocalRef(env, old);
         }
@@ -704,7 +707,7 @@
 
     /* Copy the final results into an appropriately-sized array */
     old = rv;
-    rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL);
+    rv = (*env)->NewObjectArray(env, len, str_class, NULL);
     if (rv == NULL)
         return NULL; /* error */
     if (JNU_CopyObjectArray(env, rv, old, len) < 0)
--- a/src/windows/native/sun/nio/ch/DatagramChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/DatagramChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -45,18 +45,28 @@
 Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz)
 {
     clazz = (*env)->FindClass(env, "java/net/InetSocketAddress");
+    CHECK_NULL(clazz);
     isa_class = (*env)->NewGlobalRef(env, clazz);
+    if (isa_class == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
     isa_ctorID = (*env)->GetMethodID(env, clazz, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
+    CHECK_NULL(isa_ctorID);
 
     clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl");
+    CHECK_NULL(clazz);
     dci_senderID = (*env)->GetFieldID(env, clazz, "sender",
                                       "Ljava/net/SocketAddress;");
+    CHECK_NULL(dci_senderID);
     dci_senderAddrID = (*env)->GetFieldID(env, clazz,
                                           "cachedSenderInetAddress",
                                           "Ljava/net/InetAddress;");
+    CHECK_NULL(dci_senderAddrID);
     dci_senderPortID = (*env)->GetFieldID(env, clazz,
                                           "cachedSenderPort", "I");
+    CHECK_NULL(dci_senderPortID);
 }
 
 /*
@@ -185,17 +195,11 @@
     if (senderAddr == NULL) {
         jobject isa = NULL;
         int port;
-        jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa,
-                                               &port);
-
+        jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
         if (ia != NULL) {
             isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
         }
-
-        if (isa == NULL) {
-            JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
-            return IOS_THROWN;
-        }
+        CHECK_NULL_RETURN(isa, IOS_THROWN);
 
         // update cachedSenderInetAddress/cachedSenderPort
         (*env)->SetObjectField(env, this, dci_senderAddrID, ia);
--- a/src/windows/native/sun/nio/ch/FileKey.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/FileKey.c	Mon Feb 03 14:00:43 2014 +0000
@@ -38,9 +38,9 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz)
 {
-    key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J");
-    key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J");
-    key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J");
+    CHECK_NULL(key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J"));
+    CHECK_NULL(key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J"));
+    CHECK_NULL(key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J"));
 }
 
 
--- a/src/windows/native/sun/nio/ch/IOUtil.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/IOUtil.c	Mon Feb 03 14:00:43 2014 +0000
@@ -52,9 +52,9 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
 {
-    clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
-    fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
-    handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
+    CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
+    CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
+    CHECK_NULL(handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"));
 }
 
 /**************************************************************
--- a/src/windows/native/sun/nio/ch/Iocp.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/Iocp.c	Mon Feb 03 14:00:43 2014 +0000
@@ -46,16 +46,15 @@
     jclass clazz;
 
     clazz = (*env)->FindClass(env, "sun/nio/ch/Iocp$CompletionStatus");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
-    if (completionStatus_error == NULL) return;
+    CHECK_NULL(completionStatus_error);
     completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
-    if (completionStatus_bytesTransferred == NULL) return;
+    CHECK_NULL(completionStatus_bytesTransferred);
     completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I");
-    if (completionStatus_completionKey == NULL) return;
+    CHECK_NULL(completionStatus_completionKey);
     completionStatus_overlapped = (*env)->GetFieldID(env, clazz, "overlapped", "J");
+    CHECK_NULL(completionStatus_overlapped);
 }
 
 JNIEXPORT jint JNICALL
--- a/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -56,12 +56,20 @@
 Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass cls)
 {
     cls = (*env)->FindClass(env, "java/io/FileDescriptor");
+    CHECK_NULL(cls);
     fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I");
+    CHECK_NULL(fd_fdID);
 
     cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
+    CHECK_NULL(cls);
     isa_class = (*env)->NewGlobalRef(env, cls);
+    if (isa_class == NULL) {
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
     isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
+    CHECK_NULL(isa_ctorID);
 }
 
 JNIEXPORT void JNICALL
@@ -99,10 +107,10 @@
 
     (*env)->SetIntField(env, newfdo, fd_fdID, newfd);
     remote_ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, (int *)&remote_port);
+    CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
 
-    isa = (*env)->NewObject(env, isa_class, isa_ctorID,
-                            remote_ia, remote_port);
+    isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
+    CHECK_NULL_RETURN(isa, IOS_THROWN);
     (*env)->SetObjectArrayElement(env, isaa, 0, isa);
-
     return 1;
 }
--- a/src/windows/native/sun/nio/ch/SocketChannelImpl.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/ch/SocketChannelImpl.c	Mon Feb 03 14:00:43 2014 +0000
@@ -42,8 +42,8 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_SocketChannelImpl_initIDs(JNIEnv *env, jclass cls)
 {
-    cls = (*env)->FindClass(env, "java/net/InetAddress");
-    ia_addrID = (*env)->GetFieldID(env, cls, "address", "I");
+    CHECK_NULL(cls = (*env)->FindClass(env, "java/net/InetAddress"));
+    CHECK_NULL(ia_addrID = (*env)->GetFieldID(env, cls, "address", "I"));
 }
 
 jint
--- a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c	Sat Feb 01 10:27:55 2014 -0800
+++ b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c	Mon Feb 03 14:00:43 2014 +0000
@@ -111,65 +111,70 @@
     HMODULE h;
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstFile");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     findFirst_handle = (*env)->GetFieldID(env, clazz, "handle", "J");
+    CHECK_NULL(findFirst_handle);
     findFirst_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
+    CHECK_NULL(findFirst_name);
     findFirst_attributes = (*env)->GetFieldID(env, clazz, "attributes", "I");
+    CHECK_NULL(findFirst_attributes);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstStream");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     findStream_handle = (*env)->GetFieldID(env, clazz, "handle", "J");
+    CHECK_NULL(findStream_handle);
     findStream_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
+    CHECK_NULL(findStream_name);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;");
+    CHECK_NULL(volumeInfo_fsName);
     volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;");
+    CHECK_NULL(volumeInfo_volName);
     volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I");
+    CHECK_NULL(volumeInfo_volSN);
     volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I");
+    CHECK_NULL(volumeInfo_flags);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J");
+    CHECK_NULL(diskSpace_bytesAvailable);
     diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J");
+    CHECK_NULL(diskSpace_totalBytes);
     diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J");
+    CHECK_NULL(diskSpace_totalFree);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;");
+    CHECK_NULL(account_domain);
     account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
+    CHECK_NULL(account_name);
     account_use = (*env)->GetFieldID(env, clazz, "use", "I");
+    CHECK_NULL(account_use);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I");
+    CHECK_NULL(aclInfo_aceCount);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
+    CHECK_NULL(completionStatus_error);
     completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
+    CHECK_NULL(completionStatus_bytesTransferred);
     completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "J");
+    CHECK_NULL(completionStatus_completionKey);
 
     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$BackupResult");
-    if (clazz == NULL) {
-        return;
-    }
+    CHECK_NULL(clazz);
     backupResult_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
+    CHECK_NULL(backupResult_bytesTransferred);
     backupResult_context = (*env)->GetFieldID(env, clazz, "context", "J");
+    CHECK_NULL(backupResult_context);
 
     // get handle to kernel32
     if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |