harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r964001 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/net/InetSocketAddress.java test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
Date Wed, 14 Jul 2010 10:37:00 GMT
Author: odeakin
Date: Wed Jul 14 10:36:59 2010
New Revision: 964001

URL: http://svn.apache.org/viewvc?rev=964001&view=rev
Log:
To match the RI's behaviour, resolve and store the hostname when getHostName is called. Add
a flag so we do not resolve the hostname for every call to getHostName. Also add a regression
test for the behaviour.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/InetSocketAddress.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/InetSocketAddress.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/InetSocketAddress.java?rev=964001&r1=964000&r2=964001&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/InetSocketAddress.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/InetSocketAddress.java
Wed Jul 14 10:36:59 2010
@@ -34,6 +34,8 @@ public class InetSocketAddress extends S
 
     private int port;
 
+    private transient boolean gotHostname = false;
+
     /**
      * Creates a socket endpoint with the given port number {@code port} and the
      * wildcard address {@code InetAddress.ANY}. The range for valid port numbers
@@ -102,7 +104,6 @@ public class InetSocketAddress extends S
         if (needResolved) {
             try {
                 addr = InetAddress.getByName(hostname);
-                hostname = null;
             } catch (UnknownHostException e) {
                 // Ignored
             }
@@ -153,7 +154,11 @@ public class InetSocketAddress extends S
      * @return the socket endpoint hostname.
      */
     public final String getHostName() {
-        return (null != addr) ? addr.getHostName() : hostname;
+        if (addr != null && !gotHostname) {
+            gotHostname = true;
+            hostname = addr.getHostName();
+        }
+        return  hostname;
     }
 
     /**

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java?rev=964001&r1=964000&r2=964001&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
Wed Jul 14 10:36:59 2010
@@ -31,7 +31,9 @@ public class InetSocketAddressTest exten
     public void test_ConstructorLjava_lang_StringI() throws Exception {
         // regression test for Harmony-1042
         InetSocketAddress address = new InetSocketAddress("127.0.0.1", 0);
-        assertNotNull(address.getHostName());
+        assertEquals("/127.0.0.1:0", address.toString());
+        assertEquals("localhost", address.getHostName());
+        assertEquals("localhost/127.0.0.1:0", address.toString());
     }
     
     /**



Mime
View raw message