JDK-8135259 : InetAddress.getAllByName only reports "unknown error" instead of actual cause
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-09-02
  • Updated: 2016-07-21
  • Resolved: 2016-02-17
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 8
8u102 b01Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux alainodea-xps-l521x 3.13.0-46-generic #79-Ubuntu SMP Tue Mar 10 20:06:50 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

A DESCRIPTION OF THE PROBLEM :
I think I have identified a regression in network error handling from Java 7 to Java 8.

In Java 7, attempts to resolve a host unknown to the DNS server cause an UnknownHostException stating "Name or service not known".

In Java 8, attempts to resolve a host unknown to the DNS server cause an UnknownHostException stating "unknown error".

Possible root cause:
It appears that Java 7 had initialization that allowed the gai_strerror_ptr function pointer to be correctly initialized:
http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/solaris/native/java/net/net_util_md.c#l398

However, I cannot find equivalent initialization in JDK 8:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/solaris/native/java/net/net_util_md.c

REGRESSION.  Last worked in version 7u80

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file called InetAddressGetAllByName.java with the content from the source code I have listed on this case

2. Compile InetAddressGetAllByName.java:
javac InetAddressGetAllByName.java

3. Run InetAddressGetAllByName
java InetAddressGetAllByName

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The following is the 

Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1248)
	at java.net.InetAddress.getAllByName(InetAddress.java:1164)
	at java.net.InetAddress.getAllByName(InetAddress.java:1098)
	at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)
ACTUAL -
Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: unknown error
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
	at java.net.InetAddress.getAllByName(InetAddress.java:1192)
	at java.net.InetAddress.getAllByName(InetAddress.java:1126)
	at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
public class InetAddressGetAllByName {
    public static void main(String[] args) throws UnknownHostException {
        System.out.println(Arrays.toString(InetAddress.getAllByName("doesnotexist.example.com")));
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use filtered system call tracing to determine actual causes when this happens.


Comments
The issue was because of the native code changes in net_util_md.c for Solaris platform. Brief History: 1. As per the jdk7 bug JDK-6981157: An improvement was added to UnknownHostException which was integrated into jdk7-ea-b114. Bug: https://bugs.openjdk.java.net/browse/JDK-6981157 6981157: Improve UnknownHostException with EAI error details and other cleanups. 2. Later in jdk8 as per the bug JDK-7112670: Inet4AddressImpl.c implementation was changed to be consistent with Inet6AddressImpl.c (like using getaddrinfo instead of gethostbyname). While doing this author has removed few function pointers present in net.util.md.c since he used functions directly. While doing this the function pointer defined for getaddressinfo error namely - gai_strerror_ptr was also removed which was actually providing the actual error information. That time no issue was found because the variable declarations were not removed for any of the removed function pointer variables. This patch was integrated into jdk8-ea-b15. The corresponding bug is: https://bugs.openjdk.java.net/browse/JDK-7112670 7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo ( modernization/cleanup ) We should actually remove all the unused variable declarations from net.util.md.c and net.util.md. In UnknownHostException the 'gai_strerror_ptr' check should be replaced with the direct method call. i.e. :const char *error_string = gai_strerror(gai_error);
05-02-2016

This issue is reproducible in Linux OS. Attached test case was run on following versions and below are the results: JDK 7u80 - Pass JDK 8 -Fail JDK 8u51- Fail JDK 8u60 -Fail JDK 8u66 -Fail JDK 9ea -Pass Following is a snapshot of the results obtained with 7u80 ,8u60 and 9ea versions: 1.7.0_80 Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295) at java.net.InetAddress.getAllByName0(InetAddress.java:1248) at java.net.InetAddress.getAllByName(InetAddress.java:1164) at java.net.InetAddress.getAllByName(InetAddress.java:1098) at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) ----------------------------------------------------------------------------- 1.8.0_60 Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: unknown error at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) at java.net.InetAddress.getAllByName0(InetAddress.java:1276) at java.net.InetAddress.getAllByName(InetAddress.java:1192) at java.net.InetAddress.getAllByName(InetAddress.java:1126) at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) ------------------------------------------------------------------------------ 1.9.0-ea Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$3.lookupAllHostAddr(InetAddress.java:872) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1288) at java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:821) at java.net.InetAddress.getAllByName0(InetAddress.java:1277) at java.net.InetAddress.getAllByName(InetAddress.java:1136) at java.net.InetAddress.getAllByName(InetAddress.java:1070) at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) Moving to dev-team for further action.
09-09-2015