changeset 11437:aa919ce9e3b6

8135259: InetAddress.getAllByName only reports "unknown error" instead of actual cause Summary: Using a function call directly "gai_strerror(gai_error)" instead of using the function pointer which was declared but not initialized. Reviewed-by: chegar, coffeys, igerasim
author rpatil
date Wed, 17 Feb 2016 10:46:21 +0530
parents 7bbfd054603a
children 9dafc9f520da
files src/solaris/native/java/net/net_util_md.c src/solaris/native/java/net/net_util_md.h test/java/net/InetAddress/B6246242.java
diffstat 3 files changed, 6 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/net/net_util_md.c	Wed Feb 17 14:20:45 2016 +0300
+++ b/src/solaris/native/java/net/net_util_md.c	Wed Feb 17 10:46:21 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -68,13 +68,6 @@
 
 #include "java_net_SocketOptions.h"
 
-/* needed from libsocket on Solaris 8 */
-
-getaddrinfo_f getaddrinfo_ptr = NULL;
-freeaddrinfo_f freeaddrinfo_ptr = NULL;
-gai_strerror_f gai_strerror_ptr = NULL;
-getnameinfo_f getnameinfo_ptr = NULL;
-
 /*
  * EXCLBIND socket options only on Solaris
  */
@@ -434,8 +427,7 @@
     int size;
     char *buf;
     const char *format = "%s: %s";
-    const char *error_string =
-        (gai_strerror_ptr == NULL) ? NULL : (*gai_strerror_ptr)(gai_error);
+    const char *error_string = gai_strerror(gai_error);
     if (error_string == NULL)
         error_string = "unknown error";
 
--- a/src/solaris/native/java/net/net_util_md.h	Wed Feb 17 14:20:45 2016 +0300
+++ b/src/solaris/native/java/net/net_util_md.h	Wed Feb 17 10:46:21 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -134,22 +134,6 @@
 #endif /* SO_FLOW_SLA */
 #endif /* __solaris__ */
 
-/* needed from libsocket on Solaris 8 */
-
-typedef int (*getaddrinfo_f)(const char *nodename, const char *servname,
-    const struct addrinfo *hints, struct addrinfo **res);
-
-typedef void (*freeaddrinfo_f)(struct addrinfo *);
-
-typedef const char * (*gai_strerror_f)(int ecode);
-
-typedef int (*getnameinfo_f)(const struct sockaddr *, size_t,
-    char *, size_t, char *, size_t, int);
-
-extern getaddrinfo_f getaddrinfo_ptr;
-extern freeaddrinfo_f freeaddrinfo_ptr;
-extern getnameinfo_f getnameinfo_ptr;
-
 void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
                                            const char* hostname,
                                            int gai_error);
--- a/test/java/net/InetAddress/B6246242.java	Wed Feb 17 14:20:45 2016 +0300
+++ b/test/java/net/InetAddress/B6246242.java	Wed Feb 17 10:46:21 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6246242
+ * @bug 6246242 8135259
  * @summary UnknownHostException contains wrong error message
  */
 
@@ -36,7 +36,7 @@
             a = InetAddress.getByName("foo.bar");
         } catch (UnknownHostException e) {
             String s = e.getMessage();
-            if (s.indexOf("foo.bar: foo.bar") >= 0)
+            if (s.contains("foo.bar: foo.bar") || s.contains("unknown error"))
                 throw new RuntimeException("UnknownHostException has wrong message: " + s);
         }
     }