harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r689476 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/InetAddress.java test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
Date Wed, 27 Aug 2008 13:23:58 GMT
Author: tellison
Date: Wed Aug 27 06:23:57 2008
New Revision: 689476

URL: http://svn.apache.org/viewvc?rev=689476&view=rev
Log:
Getting InetAddresses by name should return specific subtypes corresponding to IPv4 or IPv6
addresses rather than the generic supertype.  Although this is not required by the spec it
is how the RI behaves so matching to avoid spurious incompatibilities.

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java?rev=689476&r1=689475&r2=689476&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java Wed
Aug 27 06:23:57 2008
@@ -221,6 +221,12 @@
         }
 
         byte[] hBytes = Inet6Util.createByteArrayFromIPAddressString(host);
+        if (hBytes.length == 4) {
+            return (new InetAddress[] { new Inet4Address(hBytes) });
+        } else if (hBytes.length == 16) {
+            return (new InetAddress[] { new Inet6Address(hBytes) });
+        }
+
         return (new InetAddress[] { new InetAddress(hBytes) });
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java?rev=689476&r1=689475&r2=689476&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
Wed Aug 27 06:23:57 2008
@@ -185,6 +185,7 @@
     /**
      * @tests java.net.InetAddress#getAllByName(java.lang.String)
      */
+    @SuppressWarnings("nls")
     public void test_getAllByNameLjava_lang_String() throws Exception {
         // Test for method java.net.InetAddress []
         // java.net.InetAddress.getAllByName(java.lang.String)
@@ -225,6 +226,14 @@
         assertEquals("Assert 2: No loopback address", 1, ia.length);
         assertTrue("Assert 3: getAllByName(\"\") not loopback",
                 ia[0].isLoopbackAddress());
+        
+        // Check that getting addresses by dotted string distinguish
+        // IPv4 and IPv6 subtypes.
+        InetAddress[] list = InetAddress.getAllByName("192.168.0.1");
+        for (InetAddress addr : list) {
+            assertFalse("Expected subclass returned",
+                    addr.getClass().equals(InetAddress.class));
+        }
     }
 
     /**



Mime
View raw message