JDK-7006496 : Use modern Windows API to retrieve OS DNS servers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 6u23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2010-12-13
  • Updated: 2022-01-20
  • Resolved: 2020-01-24
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 15
15 b08Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Notebook with a wired and a wireless network card, both configured using DHCP. The wireless network card is disabled using its hardware switch, thus only the wired network is active.
Relevant output of ipconfig:
Wireless LAN adapter Wireless Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) WiFi Link 5100 AGN
   Physical Address. . . . . . . . . : 00-xx-xx-xx-xx-48
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : mydomain.ch
   Description . . . . . . . . . . . : Intel(R) 82567LM Gigabit Network Connection
   Physical Address. . . . . . . . . : 00-xx-xx-xx-xx-20
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::f88d:bxx8:8xx2:9xx7%11(Preferred)
   IPv4 Address. . . . . . . . . . . : 10.212.136.24(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Montag, 13. Dezember 2010 09:26:55
   Lease Expires . . . . . . . . . . : Montag, 13. Dezember 2010 23:16:57
   Default Gateway . . . . . . . . . : 10.212.136.1
   DHCP Server . . . . . . . . . . . : 10.51.2.32
   DHCPv6 IAID . . . . . . . . . . . : 234890596
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-12-xx-xx-xx-xx-xx-xx-xx-xx-20
   DNS Servers . . . . . . . . . . . : 10.51.2.32
                                       10.51.2.33
   NetBIOS over Tcpip. . . . . . . . : Enabled

A DESCRIPTION OF THE PROBLEM :
The call to new sun.net.dns.ResolverConfigurationImpl().nameservers(), which is used by various libraries, returns and additional nameserver. Specifically it returns the value last assigned by DHCP to the currently disabled wireless adapter (read from the registry value HKLM\SYSTEM\CurrentControlSet\services\TcpIp\Parameters\DhcpNameServer).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Take a computer using two network cards
- Get both connected and assigned an IP Address and DNS servers via DHCP (the DNS Servers of the disconnected card MUST NOT be reachable via the address of the still connected card)
- Disconnect one of the two connections

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
10.51.2.32
10.51.2.33

(as per the output of IPConfig)
ACTUAL -
192.168.61.1
10.51.2.32
10.51.2.33


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class DNS {
	public static void main(String[] args) {
		for(Object s : sun.net.dns.ResolverConfiguration.open().nameservers()){
			System.out.println(s);
		}
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None. But resolve in JVM by implementing the lookup using the IPHlpApi and method GetAdaptersAddresses, checking its results for OperStatus==IfOperStatusUp and the field FirstDnsServerAddress (see http://msdn.microsoft.com/en-us/library/aa365915%28VS.85%29.aspx).

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/559fcd53e782 User: aefimov Date: 2020-01-24 16:52:09 +0000
24-01-2020