JDK-4379243 : InetAddress.toString() causes DNS lookup -- can result in delay
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-10-13
  • Updated: 2001-01-04
  • Resolved: 2001-01-04
Related Reports
Duplicate :  
Description

Name: skT45625			Date: 10/13/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


Calling the java.net.InetAddress.toString() method returns both the hostname
and the host address, separated by a slash.  To obtain the hostname, a DNS
lookup may be performed.

The documentation for toString() only says, "Converts this IP address to a
String."  It doesn't indicate that a DNS lookup for the hostname could happen.

The toString() method should be changed to return only the result of
getHostAddress().  A DNS lookup can fail, and can take several seconds to
evaluate.  In our case, several hundred machines are connecting within the
space of a few seconds, and for each we log a message including the result of
the InetAddress.toString().  The DNS lookup fails for many of these machines,
and it takes over 8 minutes to handle the connections.

Please either: 1) remove the getHostName() call from within toString(); or 2)
modify the documentation so it is clear that both getHostAddress() and
getHostName() are being called from within toString(), and that getHostName()
can result in a DNS lookup if the name is not already cached.
(Review ID: 110847) 
======================================================================

Comments
WORK AROUND Name: skT45625 Date: 10/13/2000 Subclass InetAddress and replace the toString() function with a call to getHostAddress(). ======================================================================
11-06-2004