JDK-6991580 : IPv6 Nameservers in resolv.conf throws NumberFormatException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 7,8u45,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2010-10-13
  • Updated: 2024-02-05
  • Resolved: 2015-04-21
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 7 JDK 8 JDK 9
7u261Fixed 8u60Fixed 9 b62Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
openjdk version "1.7.0-alpha"
OpenJDK Runtime Environment (build 1.7.0-alpha-106)
OpenJDK 64-Bit Server VM (build 19.0-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Various Linux systems e.g. Ubuntu 10.04 or Gentoo Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
A nameserver which is accessible via IPv6 is required to reproduce this bug.

A DESCRIPTION OF THE PROBLEM :
Linux systems don't require and moreover don't allow to use IPv6 literal host names within delimiting brackets for nameservers in /etc/resolv.conf. So IPv6 entries have the form:
	nameserver 2001:0db8:85a3:08d3:1319:8a2e:0370:7344

When trying to use a nameserver via IPv6 a NumberFormatException is thrown.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Setup a Linux system with IPv6 and a nameserver via IPv6.
2. Compile the provided NSLookup Class
3. Run the application e.g. via java NSLookup A openjdk.org

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected output: openjdk.org: 192.9.170.173
ACTUAL -
A NumberFormatException is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NumberFormatException: For input string: "0db8:85a3:08d3:1319:8a2e:0370:7344"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:481)
	at java.lang.Integer.parseInt(Integer.java:514)
	at com.sun.jndi.dns.DnsClient.<init>(DnsClient.java:122)
	at com.sun.jndi.dns.Resolver.<init>(Resolver.java:61)
	at com.sun.jndi.dns.DnsContext.getResolver(DnsContext.java:570)
	at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:430)
	at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:231)
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:139)
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:127)
	at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:140)
	at NSLookup.main(NSLookup.java:14)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.naming.directory.*;
import java.util.Hashtable;

public class NSLookup {
	public static void main(String[] args) {
		if (args.length != 2) {
			System.out.println("We need 2 arguments: <TYPE> <DOMAIN>");
			return;
		}
		try {
			Hashtable<String,String> env = new Hashtable<String,String>();
			env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
			DirContext context = new InitialDirContext(env);
			Attributes dnsLookup = context.getAttributes(args[1], new String[]{args[0]});
			Attribute records = dnsLookup.get(args[0]);
			if (records == null) {
				System.out.println("No " + args[0] + " record found for domain: " + args[1]);
				return;
			}
			for (int i = 0; i < records.size(); i++) {
				System.out.println(args[1] + ": " + records.get(i));
			}
			context.close();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
---------- END SOURCE ----------
See the discussion of net-dev mailing list:
  http://mail.openjdk.java.net/pipermail/net-dev/2010-October/002258.html

Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/4be070b8aaba User: lana Date: 2015-04-29 18:01:57 +0000
29-04-2015

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/4be070b8aaba User: michaelm Date: 2015-04-21 13:44:24 +0000
21-04-2015

Proposed for review: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-April/032912.html
20-04-2015

See also this downstream fedora bug: https://bugzilla.redhat.com/show_bug.cgi?id=1210739
16-04-2015

This issue affects any Linux system I believe.
16-04-2015

Proposed fix.
16-04-2015