OpenJDK / jdk / jdk
changeset 13787:19d54bca65d7
7032247: java/net/InetAddress/GetLocalHostWithSM.java fails if hostname resolves to loopback address
Summary: TESTBUG
Reviewed-by: chegar, alanb
Contributed-by: Eric Wang <yiming.wang@oracle.com>
author | chegar |
---|---|
date | Fri, 07 Sep 2012 14:00:31 +0100 |
parents | dfe9a95e1c30 |
children | 3f38e525f30a |
files | jdk/test/java/net/InetAddress/GetLocalHostWithSM.java |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/test/java/net/InetAddress/GetLocalHostWithSM.java Fri Sep 07 10:24:22 2012 +0800 +++ b/jdk/test/java/net/InetAddress/GetLocalHostWithSM.java Fri Sep 07 14:00:31 2012 +0100 @@ -41,14 +41,13 @@ public static void main(String[] args) throws Exception { // try setting the local hostname - try { - System.setProperty("host.name", InetAddress. - getLocalHost(). - getHostName()); - } catch (UnknownHostException e) { - System.out.println("Cannot find the local hostname, " + - "no nameserver entry found"); + InetAddress localHost = InetAddress.getLocalHost(); + if (localHost.isLoopbackAddress()) { + System.err.println("Local host name is resolved into a loopback address. Quit now!"); + return; } + System.setProperty("host.name", localHost. + getHostName()); String policyFileName = System.getProperty("test.src", ".") + "/" + "policy.file"; System.setProperty("java.security.policy", policyFileName); @@ -66,6 +65,7 @@ new MyAction(), null); if (localHost1.equals(localHost2)) { + System.out.println("localHost1 = " + localHost1); throw new RuntimeException("InetAddress.getLocalHost() test " + " fails. localHost2 should be " + " the real address instead of " +