8235925: java/net/Socket/HttpProxy.java fails on IPv4 only hosts and other small cleanups

HttpProxy test is fixed to take into account the possibility that the host may be configured with IPv4 only

Reviewed-by: chegar
This commit is contained in:
Daniel Fuchs 2019-12-17 16:11:16 +01:00
parent ee5777c700
commit e16d4a45b0
3 changed files with 6 additions and 2 deletions

View File

@ -91,6 +91,10 @@ public class HttpProxy {
this.proxyPort = proxyPort; this.proxyPort = proxyPort;
} }
static boolean canUseIPv6() {
return IPSupport.hasIPv6() && !IPSupport.preferIPv4Stack();
}
void test() throws Exception { void test() throws Exception {
InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort); InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
Proxy httpProxy = new Proxy(Proxy.Type.HTTP, proxyAddress); Proxy httpProxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
@ -101,7 +105,7 @@ public class HttpProxy {
externalAddresses.add( externalAddresses.add(
new InetSocketAddress(InetAddress.getLocalHost(), ss.getLocalPort())); new InetSocketAddress(InetAddress.getLocalHost(), ss.getLocalPort()));
if (!"true".equals(System.getProperty("java.net.preferIPv4Stack"))) { if (canUseIPv6()) {
byte[] bytes = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; byte[] bytes = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
var address = InetAddress.getByAddress(bytes); var address = InetAddress.getByAddress(bytes);
externalAddresses.add( externalAddresses.add(

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8036979 8072384 8044773 8225214 8233296 * @bug 8036979 8072384 8044773 8225214 8233296 8234083
* @library /test/lib * @library /test/lib
* @requires !vm.graal.enabled * @requires !vm.graal.enabled
* @run main/othervm -Xcheck:jni OptionsTest * @run main/othervm -Xcheck:jni OptionsTest