# HG changeset patch # User michaelm # Date 1429623417 -3600 # Node ID 2a735486f81288c62a99edb801f7395009f4a47e # Parent ad35f9986f75657b88b9200e09a9abfbbf62b8a8 6991580: IPv6 Nameservers in resolv.conf throws NumberFormatException Reviewed-by: michaelm, andrew Contributed-by: sgehwolf@redhat.com diff -r ad35f9986f75 -r 2a735486f812 jdk/src/java.base/unix/classes/sun/net/dns/ResolverConfigurationImpl.java --- a/jdk/src/java.base/unix/classes/sun/net/dns/ResolverConfigurationImpl.java Tue Apr 21 14:23:58 2015 +0100 +++ b/jdk/src/java.base/unix/classes/sun/net/dns/ResolverConfigurationImpl.java Tue Apr 21 14:36:57 2015 +0100 @@ -85,6 +85,15 @@ if (val.charAt(0) == '#' || val.charAt(0) == ';') { break; } + if ("nameserver".equals(keyword)) { + if (val.indexOf(':') >= 0 && + val.indexOf('.') < 0 && // skip for IPv4 literals with port + val.indexOf('[') < 0 && + val.indexOf(']') < 0 ) { + // IPv6 literal, in non-BSD-style. + val = "[" + val + "]"; + } + } ll.add(val); if (--maxvalues == 0) { break; diff -r ad35f9986f75 -r 2a735486f812 jdk/test/javax/naming/dns/IPv6NameserverPlatformParsingTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/naming/dns/IPv6NameserverPlatformParsingTest.java Tue Apr 21 14:36:57 2015 +0100 @@ -0,0 +1,81 @@ +import java.lang.reflect.Field; +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.spi.NamingManager; + +import com.sun.jndi.dns.DnsContext; + +/** + * @test + * @bug 6991580 + * @summary IPv6 Nameservers in resolv.conf throws NumberFormatException + * @run main/manual IPv6NameserverPlatformParsingTest + * + * In order to run this test be sure to place, for example, the following + * snippet into your platform's {@code /etc/resolv.conf}: + *
+ * nameserver 127.0.0.1 + * nameserver 2001:4860:4860::8888 + * nameserver [::1]:5353 + * nameserver 127.0.0.1:5353 + *+ * + * Then, run this test as manual jtreg test. + * + * @author Severin Gehwolf + * + */ +public class IPv6NameserverPlatformParsingTest { + + private static boolean foundIPv6 = false; + + public static void main(String[] args) { + Hashtable