From 3c035b0aacf8a8c684315f310a5ef9504b9c8b5e Mon Sep 17 00:00:00 2001
From: Brian Burkhalter <brian.burkhalter@oracle.com>
Date: Tue, 15 Oct 2013 16:45:04 -0700
Subject: [PATCH] 8010371: getaddrinfo can fail with EAI_SYSTEM/EAGAIN, causes
 UnknownHostException to be thrown

Modify UHE exception message for EAI_AGAIN failures.

Reviewed-by: alanb, chegar, michaelm, dsamersoff
---
 jdk/src/solaris/native/java/net/Inet4AddressImpl.c | 3 +--
 jdk/src/windows/native/java/net/Inet4AddressImpl.c | 4 ++++
 jdk/src/windows/native/java/net/Inet6AddressImpl.c | 8 +++++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
index 9a4d32ebf96..44f3b7aa4a5 100644
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c
@@ -178,8 +178,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
 
     if (error) {
         /* report error */
-        JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
-                        (char *)hostname);
+        ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
         JNU_ReleaseStringPlatformChars(env, host, hostname);
         return NULL;
     } else {
diff --git a/jdk/src/windows/native/java/net/Inet4AddressImpl.c b/jdk/src/windows/native/java/net/Inet4AddressImpl.c
index d7cf8e5a395..97aab6f9c14 100644
--- a/jdk/src/windows/native/java/net/Inet4AddressImpl.c
+++ b/jdk/src/windows/native/java/net/Inet4AddressImpl.c
@@ -241,6 +241,10 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
           addrp++;
           i++;
         }
+    } else if (WSAGetLastError() == WSATRY_AGAIN) {
+        NET_ThrowByNameWithLastError(env,
+                                     JNU_JAVANETPKG "UnknownHostException",
+                                     hostname);
     } else {
         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
     }
diff --git a/jdk/src/windows/native/java/net/Inet6AddressImpl.c b/jdk/src/windows/native/java/net/Inet6AddressImpl.c
index c124f91f4d5..0e6fc308a44 100644
--- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c
+++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c
@@ -131,7 +131,13 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
 
     error = getaddrinfo(hostname, NULL, &hints, &res);
 
-    if (error) {
+    if (WSAGetLastError() == WSATRY_AGAIN) {
+        NET_ThrowByNameWithLastError(env,
+                                     JNU_JAVANETPKG "UnknownHostException",
+                                     hostname);
+        JNU_ReleaseStringPlatformChars(env, host, hostname);
+        return NULL;
+    } else if (error) {
         /* report error */
         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
                         (char *)hostname);