提交 9b3291b2 编写于 作者: R rpatil

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
上级 98404412
/*
* 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";
......
/*
* 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);
......
/*
* 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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册