Patch: fix URL.sameFile()

Anthony Green green@redhat.com
Sun Jun 8 15:27:00 GMT 2003


mauve's UTLTest.test_sameFile() used to fail when comparing these URLs..

	http://sources.redhat.com/mauve/testarea/index.html
	http://sources.redhat.com:80/mauve/testarea/index.html

..because the port numbers are "different".  URL.getPort() for the first 
URL is -1, which is supposed to always represent the protocol specific
default.  This patch makes URL.sameFile() sensitive to this, and adds
the missing getDefaultPort() method on our http Handler class.

Ok? (and similarly for GNU Classpath - but savannah appears to be down)

AG


2003-06-08  Anthony Green  <green@redhat.com>

	* java/net/URLStreamHandler.java (sameFile): Fix port value
	comparison.
	* java/net/URL.java (handler): Make package private.
	* gnu/gcj/protocol/http/Handler.java (getDefaultPort): New method.


Index: libjava/gnu/gcj/protocol/http/Handler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/protocol/http/Handler.java,v
retrieving revision 1.3
diff -c -u -p -r1.3 Handler.java
--- libjava/gnu/gcj/protocol/http/Handler.java	7 Mar 2000 19:55:25 -0000	1.3
+++ libjava/gnu/gcj/protocol/http/Handler.java	8 Jun 2003 15:14:42 -0000
@@ -1,6 +1,6 @@
 // Handler.java - URLStreamHandler for http protocol.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2003  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -16,7 +16,8 @@ import java.net.URLStreamHandler;
 import java.io.IOException;
 
 /**
- * @author Warren Levy <warrenl@cygnus.com>
+ * @author Warren Levy
+ * @author Anthony Green <green@redhat.com>
  * @date March 26, 1999.
  */
 
@@ -31,5 +32,10 @@ public class Handler extends URLStreamHa
   protected URLConnection openConnection(URL url) throws IOException
   {
     return new Connection(url);
+  }
+
+  protected int getDefaultPort ()
+  {
+    return 80;
   }
 }
Index: libjava/java/net/URL.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URL.java,v
retrieving revision 1.19
diff -c -u -p -r1.19 URL.java
--- libjava/java/net/URL.java	2 May 2003 09:27:59 -0000	1.19
+++ libjava/java/net/URL.java	8 Jun 2003 15:14:44 -0000
@@ -1,5 +1,5 @@
 /* URL.java -- Uniform Resource Locator Class
-   Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2002, 2003  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -147,7 +147,7 @@ public final class URL implements Serial
   /**
    * The protocol handler in use for this URL
    */
-  transient private URLStreamHandler handler;
+  transient URLStreamHandler handler;
 
   /**
    * This a table where we cache protocol handlers to avoid the overhead
Index: libjava/java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.17
diff -c -u -p -r1.17 URLStreamHandler.java
--- libjava/java/net/URLStreamHandler.java	7 Mar 2003 06:52:17 -0000	1.17
+++ libjava/java/net/URLStreamHandler.java	8 Jun 2003 15:14:44 -0000
@@ -265,7 +265,15 @@ public abstract class URLStreamHandler
       return true;
     // This comparison is very conservative.  It assumes that any
     // field can be null.
-    if (url1 == null || url2 == null || url1.getPort() != url2.getPort())
+    if (url1 == null || url2 == null)
+      return false;
+    int p1 = url1.getPort ();
+    if (p1 == -1)
+      p1 = url1.handler.getDefaultPort ();
+    int p2 = url2.getPort ();
+    if (p2 == -1)
+      p2 = url2.handler.getDefaultPort ();
+    if (p1 != p2)
       return false;
     String s1, s2;
     s1 = url1.getProtocol();


-- 
Anthony Green <green@redhat.com>
Red Hat, Inc.



More information about the Java-patches mailing list