JDK-8200719 : Cannot connect to IPv6 host when exists any active network interface without IPv6 address
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2018-03-27
  • Updated: 2019-03-19
  • Resolved: 2018-04-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 7 JDK 8
11 b10Fixed 7u211Fixed 8u202Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin MacBook-Pro-de-Joel.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

EXTRA RELEVANT SYSTEM CONFIGURATION :
WiFi Interface: IPv4 DHCP
Ethernet Interface: IPv4 DHCP, IPv6: fd00:c6a1:dea5:1::2

A DESCRIPTION OF THE PROBLEM :
When I try to connect to IPv6 host using literal address it throws a NoRouteToHostException but using ping6 its works.

In OS X Java always set a scope id in IPv6 addresses, but sometimes set a scope id for a invalid interface (without appropriated IPv6 address).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Enable two network interfaces (Wifi and Ethernet) but only set IPv6 address to one.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Correct connection to the host (no errors).
ACTUAL -
Receive a NoRouteToHostException.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.net.NoRouteToHostException: No route to host (Host unreachable)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
	at java.base/java.net.Socket.connect(Socket.java:591)
	at java.base/java.net.Socket.connect(Socket.java:540)
	at com.chaldeas.server/com.chaldeas.server.Main.main(Main.java:11)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.chaldeas.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Main {
    public static void main(String [] args) {
        try {
            Socket socket = new Socket();
            socket.connect(new InetSocketAddress("[fd00:c6a1:dea5:1::3]", 80));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I found than in OS X, Java in socketConnect native method in PlainSocketImpl class always set a default scope id to the first available interface; in this case is the Wireless interface but it hasn't a valid IPv6 address, if I put a IPv6 address in the interface, the code works, but the interface must be in the same logical network.