From 9b3291b2f147cbc76f398b9912ddb80a2bfcbca0 Mon Sep 17 00:00:00 2001 From: rpatil Date: Wed, 17 Feb 2016 10:46:21 +0530 Subject: [PATCH] 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 --- src/solaris/native/java/net/net_util_md.c | 12 ++---------- src/solaris/native/java/net/net_util_md.h | 18 +----------------- test/java/net/InetAddress/B6246242.java | 6 +++--- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/solaris/native/java/net/net_util_md.c b/src/solaris/native/java/net/net_util_md.c index 693b4b0ef..c31d29443 100644 --- a/src/solaris/native/java/net/net_util_md.c +++ b/src/solaris/native/java/net/net_util_md.c @@ -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 @@ void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, 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"; diff --git a/src/solaris/native/java/net/net_util_md.h b/src/solaris/native/java/net/net_util_md.h index 68c10d6ad..58be69078 100644 --- a/src/solaris/native/java/net/net_util_md.h +++ b/src/solaris/native/java/net/net_util_md.h @@ -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 @@ typedef struct sock_flow_props_s { #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); diff --git a/test/java/net/InetAddress/B6246242.java b/test/java/net/InetAddress/B6246242.java index 8ca80176b..77e962870 100644 --- a/test/java/net/InetAddress/B6246242.java +++ b/test/java/net/InetAddress/B6246242.java @@ -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 @@ public class B6246242 { 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); } } -- GitLab