mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8350546: Several java/net/InetAddress tests fails UnknownHostException
Backport-of: e5e39718b304de1b916fb1b11cdadd8e7fa738ac
This commit is contained in:
committed by
Vitaly Provodin
parent
e45c298753
commit
41cfe4a720
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2025, 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
|
||||
@@ -21,22 +21,24 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8135305
|
||||
* @key intermittent
|
||||
* @library /test/lib
|
||||
* @summary ensure we can't ping external hosts via loopback if
|
||||
* @run main IsReachableViaLoopbackTest
|
||||
*/
|
||||
|
||||
public class IsReachableViaLoopbackTest {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
InetAddress addr = InetAddress.getByName("localhost");
|
||||
InetAddress remoteAddr = InetAddress.getByName("bugs.openjdk.org");
|
||||
InetAddress addr = InetAddress.getLoopbackAddress();
|
||||
InetAddress remoteAddr = InetAddress.getByName("23.197.138.208"); // use literal address to avoid DNS checks
|
||||
if (!addr.isReachable(10000))
|
||||
throw new RuntimeException("Localhost should always be reachable");
|
||||
NetworkInterface inf = NetworkInterface.getByInetAddress(addr);
|
||||
@@ -54,7 +56,6 @@ public class IsReachableViaLoopbackTest {
|
||||
} else {
|
||||
System.out.println("inf == null");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unexpected exception:" + e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2025, 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
|
||||
@@ -41,7 +41,9 @@ public class getOriginalHostName {
|
||||
public static void main(String[] args) throws Exception {
|
||||
final String HOST = "dummyserver.java.net";
|
||||
InetAddress ia = null;
|
||||
ia = InetAddress.getByName(HOST);
|
||||
ia = getInetAddress(HOST);
|
||||
if (ia != null) testInetAddress(ia, HOST);
|
||||
ia = InetAddress.getByAddress(HOST, new byte[] { 1, 2, 3, 4});
|
||||
testInetAddress(ia, HOST);
|
||||
ia = InetAddress.getByName("255.255.255.0");
|
||||
testInetAddress(ia, null);
|
||||
@@ -53,6 +55,14 @@ public class getOriginalHostName {
|
||||
testInetAddress(ia, ia.getHostName());
|
||||
}
|
||||
|
||||
private static InetAddress getInetAddress(String host) {
|
||||
try {
|
||||
return InetAddress.getByName(host);
|
||||
} catch (java.net.UnknownHostException uhe) {
|
||||
System.out.println("Skipping " + host + " due to " + uhe);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void testInetAddress(InetAddress ia, String expected)
|
||||
throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user