8193419: Better Internet address support
authorvtewari
Thu, 18 Jan 2018 13:55:26 +0530
changeset 51151 d6b131d2bc8b
parent 51150 2449e681ac60
child 51152 edd69f959190
8193419: Better Internet address support Reviewed-by: chegar, rriggs, igerasim, skoivu, rhalade
src/java.base/share/native/libjava/jni_util.h
src/java.base/share/native/libnet/net_util.c
src/java.base/unix/native/libnet/Inet4AddressImpl.c
src/java.base/unix/native/libnet/Inet6AddressImpl.c
src/java.base/unix/native/libnet/NetworkInterface.c
src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c
src/java.base/unix/native/libnet/net_util_md.c
src/java.base/windows/native/libnet/Inet4AddressImpl.c
src/java.base/windows/native/libnet/Inet6AddressImpl.c
src/java.base/windows/native/libnet/NetworkInterface.c
src/java.base/windows/native/libnet/NetworkInterface_winXP.c
src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c
src/java.base/windows/native/libnet/net_util_md.c
--- a/src/java.base/share/native/libjava/jni_util.h	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/share/native/libjava/jni_util.h	Thu Jan 18 13:55:26 2018 +0530
@@ -297,6 +297,22 @@
         }                                       \
     } while (0)                                 \
 
+#define CHECK_NULL_THROW_NPE(env, x, msg)         \
+    do {                                        \
+        if ((x) == NULL) {                      \
+           JNU_ThrowNullPointerException((env), (msg));\
+           return;                              \
+        }                                       \
+    } while(0)                                  \
+
+#define CHECK_NULL_THROW_NPE_RETURN(env, x, msg, z)\
+    do {                                        \
+        if ((x) == NULL) {                      \
+           JNU_ThrowNullPointerException((env), (msg));\
+           return (z);                          \
+        }                                       \
+    } while(0)                                  \
+
 #define CHECK_NULL_RETURN(x, y)                 \
     do {                                        \
         if ((x) == NULL) {                      \
--- a/src/java.base/share/native/libnet/net_util.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/share/native/libnet/net_util.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -171,32 +171,38 @@
 
 void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
     (*env)->SetIntField(env, holder, iac_addressID, address);
 }
 
 void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
     (*env)->SetIntField(env, holder, iac_familyID, family);
 }
 
 void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
     (*env)->SetObjectField(env, holder, iac_hostNameID, host);
     (*env)->SetObjectField(env, holder, iac_origHostNameID, host);
 }
 
 int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
     return (*env)->GetIntField(env, holder, iac_addressID);
 }
 
 int getInetAddress_family(JNIEnv *env, jobject iaObj) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
     return (*env)->GetIntField(env, holder, iac_familyID);
 }
 
 jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
     jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", NULL);
     return (*env)->GetObjectField(env, holder, iac_hostNameID);
 }
 
@@ -211,7 +217,9 @@
             CHECK_NULL_RETURN(iaObj, NULL);
             address = NET_IPv4MappedToIPv4(caddr);
             setInetAddress_addr(env, iaObj, address);
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         } else {
             jboolean ret;
             iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
@@ -220,6 +228,7 @@
             if (ret == JNI_FALSE)
                 return NULL;
             setInetAddress_family(env, iaObj, java_net_InetAddress_IPv6);
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             setInet6Address_scopeid(env, iaObj, sa->sa6.sin6_scope_id);
         }
         *port = ntohs(sa->sa6.sin6_port);
@@ -227,7 +236,9 @@
         iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
         CHECK_NULL_RETURN(iaObj, NULL);
         setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         setInetAddress_addr(env, iaObj, ntohl(sa->sa4.sin_addr.s_addr));
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         *port = ntohs(sa->sa4.sin_port);
     }
     return iaObj;
@@ -238,6 +249,7 @@
 {
     jint family = getInetAddress_family(env, iaObj) ==
         java_net_InetAddress_IPv4 ? AF_INET : AF_INET6;
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     if (sa->sa.sa_family == AF_INET6) {
         jbyte *caddrNew = (jbyte *)&sa->sa6.sin6_addr;
         if (NET_IsIPv4Mapped(caddrNew)) {
@@ -247,6 +259,7 @@
             }
             addrNew = NET_IPv4MappedToIPv4(caddrNew);
             addrCur = getInetAddress_addr(env, iaObj);
+            JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
             if (addrNew == addrCur) {
                 return JNI_TRUE;
             } else {
@@ -273,6 +286,7 @@
         }
         addrNew = ntohl(sa->sa4.sin_addr.s_addr);
         addrCur = getInetAddress_addr(env, iaObj);
+        JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
         if (addrNew == addrCur) {
             return JNI_TRUE;
         } else {
--- a/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -193,7 +193,11 @@
             }
             setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in *)
                                 (iterator->ai_addr))->sin_addr.s_addr));
+            if ((*env)->ExceptionCheck(env))
+                goto cleanupAndReturn;
             setInetAddress_hostName(env, iaObj, host);
+            if ((*env)->ExceptionCheck(env))
+                goto cleanupAndReturn;
             (*env)->SetObjectArrayElement(env, ret, i++, iaObj);
             iterator = iterator->ai_next;
         }
--- a/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -198,6 +198,8 @@
                 return NULL;
             }
             setInetAddress_hostName(env, o, name);
+            if ((*env)->ExceptionCheck(env))
+                goto done;
             (*env)->SetObjectArrayElement(env, result, index, o);
             (*env)->DeleteLocalRef(env, o);
         }
@@ -355,7 +357,11 @@
                     goto cleanupAndReturn;
                 }
                 setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 setInetAddress_hostName(env, iaObj, host);
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 (*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
                 inetIndex++;
             } else if (iterator->ai_family == AF_INET6) {
@@ -376,6 +382,8 @@
                     setInet6Address_scopeid(env, iaObj, scope);
                 }
                 setInetAddress_hostName(env, iaObj, host);
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 (*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
                 inet6Index++;
             }
--- a/src/java.base/unix/native/libnet/NetworkInterface.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/unix/native/libnet/NetworkInterface.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -329,11 +329,11 @@
   (JNIEnv *env, jclass cls, jobject iaObj)
 {
     netif *ifs, *curr;
+    jobject obj = NULL;
+    jboolean match = JNI_FALSE;
     int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ?
         AF_INET : AF_INET6;
-    jobject obj = NULL;
-    jboolean match = JNI_FALSE;
-
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
     ifs = enumInterfaces(env);
     if (ifs == NULL) {
         return NULL;
@@ -351,7 +351,7 @@
                     int address1 = htonl(
                         ((struct sockaddr_in *)addrP->addr)->sin_addr.s_addr);
                     int address2 = getInetAddress_addr(env, iaObj);
-
+                    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
                     if (address1 == address2) {
                         match = JNI_TRUE;
                         break;
@@ -698,6 +698,7 @@
             if (iaObj) {
                 setInetAddress_addr(env, iaObj, htonl(
                     ((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
+                JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             } else {
                 return NULL;
             }
@@ -710,6 +711,7 @@
                     if (ia2Obj) {
                         setInetAddress_addr(env, ia2Obj, htonl(
                             ((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
+                        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
                         (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
                     } else {
                         return NULL;
--- a/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -531,9 +531,12 @@
     iaObj = NET_SockaddrToInetAddress(env, &rmtaddr, &port);
     family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
         AF_INET : AF_INET6;
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
     if (family == AF_INET) { /* this API can't handle IPV6 addresses */
         int address = getInetAddress_addr(env, iaObj);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
         setInetAddress_addr(env, addressObj, address);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
     }
     return port;
 }
@@ -1045,7 +1048,9 @@
     for (i = 0; i < len; i++) {
         addr = (*env)->GetObjectArrayElement(env, addrArray, i);
         if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
+            JNU_CHECK_EXCEPTION(env);
             in.s_addr = htonl(getInetAddress_addr(env, addr));
+            JNU_CHECK_EXCEPTION(env);
             break;
         }
     }
@@ -1095,7 +1100,7 @@
     struct in_addr in;
 
     in.s_addr = htonl( getInetAddress_addr(env, value) );
-
+    JNU_CHECK_EXCEPTION(env);
     if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
                    (const char*)&in, sizeof(in)) < 0) {
         JNU_ThrowByNameWithMessageAndLastError
@@ -1458,6 +1463,7 @@
         CHECK_NULL_RETURN(addr, NULL);
 
         setInetAddress_addr(env, addr, ntohl(in.s_addr));
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
         /*
          * For IP_MULTICAST_IF return InetAddress
@@ -1911,6 +1917,7 @@
 
 #ifdef __linux__
     if (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) {
+        JNU_CHECK_EXCEPTION(env);
         ipv6_join_leave = JNI_FALSE;
     }
 #endif
@@ -1951,6 +1958,7 @@
                 }
 
                 mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
+                JNU_CHECK_EXCEPTION(env);
                 mname.imr_address.s_addr = 0;
                 mname.imr_ifindex =  (*env)->GetIntField(env, niObj, ni_indexID);
                 mname_len = sizeof(struct ip_mreqn);
@@ -1969,11 +1977,14 @@
                 addr = (*env)->GetObjectArrayElement(env, addrArray, 0);
 
                 mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
+                JNU_CHECK_EXCEPTION(env);
 #ifdef __linux__
                 mname.imr_address.s_addr = htonl(getInetAddress_addr(env, addr));
+                JNU_CHECK_EXCEPTION(env);
                 mname.imr_ifindex = 0;
 #else
                 mname.imr_interface.s_addr = htonl(getInetAddress_addr(env, addr));
+                JNU_CHECK_EXCEPTION(env);
 #endif
                 mname_len = sizeof(struct ip_mreq);
             }
@@ -2009,6 +2020,7 @@
                 }
 
                 mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
+                JNU_CHECK_EXCEPTION(env);
                 mname.imr_address.s_addr = 0 ;
                 mname.imr_ifindex = index;
                 mname_len = sizeof(struct ip_mreqn);
@@ -2031,6 +2043,7 @@
                 mname.imr_interface.s_addr = in.s_addr;
 #endif
                 mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
+                JNU_CHECK_EXCEPTION(env);
                 mname_len = sizeof(struct ip_mreq);
             }
         }
@@ -2097,10 +2110,11 @@
         jint address;
         family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
             AF_INET : AF_INET6;
+        JNU_CHECK_EXCEPTION(env);
         if (family == AF_INET) { /* will convert to IPv4-mapped address */
             memset((char *) caddr, 0, 16);
             address = getInetAddress_addr(env, iaObj);
-
+            JNU_CHECK_EXCEPTION(env);
             caddr[10] = 0xff;
             caddr[11] = 0xff;
 
--- a/src/java.base/unix/native/libnet/net_util_md.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/unix/native/libnet/net_util_md.c	Thu Jan 18 13:55:26 2018 +0530
@@ -764,6 +764,7 @@
                           jboolean v4MappedAddress)
 {
     jint family = getInetAddress_family(env, iaObj);
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
     memset((char *)sa, 0, sizeof(SOCKETADDRESS));
 
     if (ipv6_available() &&
@@ -777,6 +778,7 @@
             // convert to IPv4-mapped address
             memset((char *)caddr, 0, 16);
             address = getInetAddress_addr(env, iaObj);
+            JNU_CHECK_EXCEPTION_RETURN(env, -1);
             if (address == INADDR_ANY) {
                 /* we would always prefer IPv6 wildcard address
                  * caddr[10] = 0xff;
@@ -871,6 +873,7 @@
             return -1;
         }
         address = getInetAddress_addr(env, iaObj);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
         sa->sa4.sin_port = htons(port);
         sa->sa4.sin_addr.s_addr = htonl(address);
         sa->sa4.sin_family = AF_INET;
--- a/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -146,7 +146,11 @@
             }
             setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in *)
                                 (iterator->ai_addr))->sin_addr.s_addr));
+            if ((*env)->ExceptionCheck(env))
+                goto cleanupAndReturn;
             setInetAddress_hostName(env, iaObj, host);
+            if ((*env)->ExceptionCheck(env))
+                goto cleanupAndReturn;
             (*env)->SetObjectArrayElement(env, ret, i++, iaObj);
             iterator = iterator->ai_next;
         }
--- a/src/java.base/windows/native/libnet/Inet6AddressImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/Inet6AddressImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -187,7 +187,11 @@
                     goto cleanupAndReturn;
                 }
                 setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 setInetAddress_hostName(env, iaObj, host);
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 (*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
                 inetIndex++;
             } else if (iterator->ai_family == AF_INET6) {
@@ -208,6 +212,8 @@
                     setInet6Address_scopeid(env, iaObj, scope);
                 }
                 setInetAddress_hostName(env, iaObj, host);
+                if ((*env)->ExceptionCheck(env))
+                    goto cleanupAndReturn;
                 (*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
                 inet6Index++;
             }
--- a/src/java.base/windows/native/libnet/NetworkInterface.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/NetworkInterface.c	Thu Jan 18 13:55:26 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -586,6 +586,7 @@
             /* default ctor will set family to AF_INET */
 
             setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             if (addrs->mask != -1) {
               ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
               if (ibObj == NULL) {
@@ -599,6 +600,7 @@
                 return NULL;
               }
               setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
+              JNU_CHECK_EXCEPTION_RETURN(env, NULL);
               (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
               (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
               (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
@@ -754,8 +756,9 @@
     (JNIEnv *env, jclass cls, jobject iaObj)
 {
     netif *ifList, *curr;
+    jobject netifObj = NULL;
     jint addr = getInetAddress_addr(env, iaObj);
-    jobject netifObj = NULL;
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
     if (ipv6_available()) {
--- a/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Thu Jan 18 13:55:26 2018 +0530
@@ -584,7 +584,7 @@
             /* default ctor will set family to AF_INET */
 
             setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
-
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
             if (ibObj == NULL) {
               free_netaddr(netaddrP);
@@ -597,6 +597,7 @@
               return NULL;
             }
             setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
             (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
             (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
             (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
--- a/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Thu Jan 18 13:55:26 2018 +0530
@@ -228,7 +228,7 @@
                         "Protocol family not supported");
         return;
     }
-
+    JNU_CHECK_EXCEPTION(env);
     if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
         return;
@@ -344,6 +344,7 @@
     }
 
     family = getInetAddress_family(env, address);
+    JNU_CHECK_EXCEPTION(env);
     if (family == java_net_InetAddress_IPv6 && !ipv6_available()) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
                         "Protocol family not supported");
@@ -455,6 +456,7 @@
     }
 
     family = getInetAddress_family(env, iaObj);
+    JNU_CHECK_EXCEPTION(env);
     if (family == java_net_InetAddress_IPv4) {
         fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
     } else {
@@ -584,6 +586,7 @@
         return -1;
     } else {
         address = getInetAddress_addr(env, addressObj);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
         /* We only handle IPv4 for now. Will support IPv6 once its in the os */
         family = AF_INET;
     }
@@ -657,7 +660,9 @@
         return 0;
     }
     setInetAddress_addr(env, addressObj, ntohl(remote_addr.sa4.sin_addr.s_addr));
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
     setInetAddress_family(env, addressObj, java_net_InetAddress_IPv4);
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
 
     /* return port */
     return ntohs(remote_addr.sa4.sin_port);
@@ -1349,6 +1354,7 @@
         int fam;
         addr = (*env)->GetObjectArrayElement(env, addrArray, i);
         fam = getInetAddress_family(env, addr);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
         if (fam == family) {
             *iaddr = addr;
             return 0;
@@ -1367,6 +1373,7 @@
     }
 
     iaddr->s_addr = htonl(getInetAddress_addr(env, addr));
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
     return 0;
 }
 
@@ -1471,6 +1478,7 @@
             struct in_addr in;
 
             in.s_addr = htonl(getInetAddress_addr(env, value));
+            JNU_CHECK_EXCEPTION(env);
             if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
                                (const char*)&in, sizeof(in)) < 0) {
                 JNU_ThrowByNameWithMessageAndLastError
@@ -1712,7 +1720,7 @@
         CHECK_NULL_RETURN(addr, NULL);
 
         setInetAddress_addr(env, addr, ntohl(in.s_addr));
-
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         /*
          * For IP_MULTICAST_IF return InetAddress
          */
--- a/src/java.base/windows/native/libnet/net_util_md.c	Wed Jul 18 14:44:04 2018 -0700
+++ b/src/java.base/windows/native/libnet/net_util_md.c	Thu Jan 18 13:55:26 2018 +0530
@@ -794,6 +794,7 @@
                           jboolean v4MappedAddress)
 {
     jint family = getInetAddress_family(env, iaObj);
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
     memset((char *)sa, 0, sizeof(SOCKETADDRESS));
 
     if (ipv6_available() &&
@@ -808,6 +809,7 @@
             // convert to IPv4-mapped address
             memset((char *)caddr, 0, 16);
             address = getInetAddress_addr(env, iaObj);
+            JNU_CHECK_EXCEPTION_RETURN(env, -1);
             if (address == INADDR_ANY) {
                 /* we would always prefer IPv6 wildcard address
                  * caddr[10] = 0xff;
@@ -846,6 +848,7 @@
             return -1;
         }
         address = getInetAddress_addr(env, iaObj);
+        JNU_CHECK_EXCEPTION_RETURN(env, -1);
         sa->sa4.sin_port = htons((short)port);
         sa->sa4.sin_addr.s_addr = (u_long)htonl(address);
         sa->sa4.sin_family = AF_INET;