harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r960591 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/net/URLStreamHandler.java test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Date Mon, 05 Jul 2010 13:16:49 GMT
Author: tellison
Date: Mon Jul  5 13:16:49 2010
New Revision: 960591

URL: http://svn.apache.org/viewvc?rev=960591&view=rev
Log:
Fix for HARMONY-6556 ([classlib][luni] URL.equals(Object) returns false when host and address
are null)

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

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java?rev=960591&r1=960590&r2=960591&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
Mon Jul  5 13:16:49 2010
@@ -399,17 +399,20 @@ public abstract class URLStreamHandler {
      *         otherwise.
      */
     protected boolean hostsEqual(URL url1, URL url2) {
-        String host1 = getHost(url1), host2 = getHost(url2);
-        if (host1 != null && host1.equalsIgnoreCase(host2)) {
-            return true;
-        }
-        // Compare host address if the host name is not equal.
+        // Compare by addresses if known.
         InetAddress address1 = getHostAddress(url1);
         InetAddress address2 = getHostAddress(url2);
-        if (address1 != null && address1.equals(address2)) {
+        if (address1 != null && address2 != null) {
+            return address1.equals(address2);
+        }
+
+        // Compare by name.
+        String host1 = getHost(url1);
+        String host2 = getHost(url2);
+        if (host1 == null && host2 == null) {
             return true;
         }
-        return false;
+        return host1 != null && host1.equalsIgnoreCase(host2);
     }
 
     /**
@@ -450,7 +453,7 @@ public abstract class URLStreamHandler {
     }
 
     /*
-     * If the URL host is empty while protocal is file, the host is regarded as
+     * If the URL host is empty while protocol is file, the host is regarded as
      * localhost.
      */
     private static String getHost(URL url) {

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.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/URLTest.java?rev=960591&r1=960590&r2=960591&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Mon Jul  5 13:16:49 2010
@@ -716,20 +716,27 @@ public class URLTest extends TestCase {
     /**
      * @tests java.net.URL#equals(java.lang.Object)
      */
-    public void test_equalsLjava_lang_Object() {
-        // Test for method boolean java.net.URL.equals(java.lang.Object)
-        try {
-            u = new URL("http://www.apache.org:8080/dir::23??????????test.html");
-            u1 = new URL(
-                    "http://www.apache.org:8080/dir::23??????????test.html");
-            assertTrue("A) equals returns false for two identical URLs", u
-                    .equals(u1));
-            assertTrue("return true for null comaprison", !u1.equals(null));
-            u = new URL("ftp://www.apache.org:8080/dir::23??????????test.html");
-            assertTrue("Returned true for non-equal URLs", !u.equals(u1));
-        } catch (MalformedURLException e) {
-            fail("MalformedURLException during equals test : " + e.getMessage());
-        }
+    public void test_equalsLjava_lang_Object() throws MalformedURLException {
+        u = new URL("http://www.apache.org:8080/dir::23??????????test.html");
+        u1 = new URL("http://www.apache.org:8080/dir::23??????????test.html");
+        assertTrue("A) equals returns false for two identical URLs", u
+                .equals(u1));
+        assertTrue("return true for null comparison", !u1.equals(null));
+        u = new URL("ftp://www.apache.org:8080/dir::23??????????test.html");
+        assertTrue("Returned true for non-equal URLs", !u.equals(u1));
+
+        // Regression for HARMONY-6556
+        u = new URL("file", null, 0, "/test.txt");
+        u1 = new URL("file", null, 0, "/test.txt");
+        assertEquals(u, u1);
+        
+        u = new URL("file", "first.invalid", 0, "/test.txt");
+        u1 = new URL("file", "second.invalid", 0, "/test.txt");
+        assertFalse(u.equals(u1));
+        
+        u = new URL("file", "harmony.apache.org", 0, "/test.txt");
+        u1 = new URL("file", "www.apache.org", 0, "/test.txt");
+        assertEquals(u, u1);
     }
 
     /**



Mime
View raw message