This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java.net URL stuff


Hi list,

I have fixed some URL stuff in java.net. Please review and comment.


Michael
-- 
Homepage: http://www.worldforge.org/
GPG-key: http://konqueror.dyndns.org/~mkoch/michael.gpg
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1484
diff -u -r1.1484 ChangeLog
--- ChangeLog	10 Oct 2002 12:08:36 -0000	1.1484
+++ ChangeLog	10 Oct 2002 16:18:05 -0000
@@ -1,3 +1,21 @@
+2002-10-11  Michael Koch  <konqueror@gmx.de>
+
+	* java/net/URL.java
+	(URL): Activate SecurityManager checks.
+	(equals): Use URLStreamHandler implementation instead of doing it
+	alone. This allows special protocol stream handlers to change default
+	behaviour.
+	(hashCode): Use URLStreamHandler implementation instead of doing it
+	alone. This allows special protocol stream handlers to change default
+	behaviour.
+	* java/net/URLStreamHandler.java
+	(equals): Implemented default URL equality check.
+	(hostsEqual): Implemented default URL equality check.
+	(hashCode): Implemented default URL hashCode algorithm.
+	* java/net/natPlainDatagramSocketImpl.cc:
+	No lines longer then 80 characters.
+	
+
 2002-10-10  Michael Koch  <konqueror@gmx.de>
 
 	* javax/swing/AbstractListModel.java
Index: java/net/URL.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URL.java,v
retrieving revision 1.13
diff -u -r1.13 URL.java
--- java/net/URL.java	5 Oct 2002 07:49:08 -0000	1.13
+++ java/net/URL.java	10 Oct 2002 16:18:05 -0000
@@ -98,14 +98,9 @@
 
     if (handler != null)
       {
-	// TODO12: Need SecurityManager.checkPermission and
-	// TODO12: java.net.NetPermission from JDK 1.2 to be implemented.
-	// Throw an exception if an extant security mgr precludes
-	// specifying a StreamHandler.
-	//
-	// SecurityManager s = System.getSecurityManager();
-	// if (s != null)
-	//   s.checkPermission(NetPermission("specifyStreamHandler"));
+	SecurityManager s = System.getSecurityManager ();
+	if (s != null)
+	  s.checkPermission (new NetPermission ("specifyStreamHandler"));
 
         this.handler = handler;
       }
@@ -234,14 +229,9 @@
 
     if (handler != null)
       {
-	// TODO12: Need SecurityManager.checkPermission and
-	// TODO12: java.net.NetPermission from JDK 1.2 to be implemented.
-	// Throw an exception if an extant security mgr precludes
-	// specifying a StreamHandler.
-	//
-	// SecurityManager s = System.getSecurityManager();
-	// if (s != null)
-	//   s.checkPermission(NetPermission("specifyStreamHandler"));
+	SecurityManager s = System.getSecurityManager ();
+	if (s != null)
+	  s.checkPermission (new NetPermission ("specifyStreamHandler"));
 
         this.handler = handler;
       }
@@ -270,24 +260,8 @@
       return false;
 
     URL uObj = (URL) obj;
-    
-    // This comparison is very conservative.  It assumes that any
-    // field can be null.
-    return (port == uObj.port
-	    && ((protocol == null && uObj.protocol == null)
-		|| (protocol != null && protocol.equals(uObj.protocol)))
-	    && ((userInfo == null && uObj.userInfo == null)
-                || (userInfo != null && userInfo.equals(uObj.userInfo)))
-	    && ((authority == null && uObj.authority == null)
-                || (authority != null && authority.equals(uObj.authority)))
-	    && ((host == null && uObj.host == null)
-		|| (host != null && host.equals(uObj.host)))
-	    && ((file == null && uObj.file == null)
-		|| (file != null && file.equals(uObj.file)))
-	    && ((query == null && uObj.query == null)
-                || (query != null && query.equals(uObj.query)))
-	    && ((ref == null && uObj.ref == null)
-		|| (ref != null && ref.equals(uObj.ref))));
+
+    return handler.equals (this, uObj);
   }
 
   /**
@@ -412,8 +386,7 @@
     if (hashCode != 0)
       return hashCode;		// Use cached value if available.
     else
-      return (protocol.hashCode() + ((host == null) ? 0 : host.hashCode()) +
-	port + file.hashCode());
+      return handler.hashCode (this);
   }
 
   /**
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.11
diff -u -r1.11 URLStreamHandler.java
--- java/net/URLStreamHandler.java	10 Oct 2002 05:19:22 -0000	1.11
+++ java/net/URLStreamHandler.java	10 Oct 2002 16:18:05 -0000
@@ -234,8 +234,30 @@
    */
   protected boolean equals (URL url1, URL url2)
   {
-    // FIXME: implement this
-    return false;
+    // This comparison is very conservative.  It assumes that any
+    // field can be null.
+    return (url1.getPort () == url2.getPort ()
+	    && ((url1.getProtocol () == null && url2.getProtocol () == null)
+		|| (url1.getProtocol () != null
+			&& url1.getProtocol ().equals (url2.getProtocol ())))
+	    && ((url1.getUserInfo () == null && url2.getUserInfo () == null)
+                || (url1.getUserInfo () != null
+			&& url1.getUserInfo ().equals(url2.getUserInfo ())))
+	    && ((url1.getAuthority () == null && url2.getAuthority () == null)
+                || (url1.getAuthority () != null
+			&& url1.getAuthority ().equals(url2.getAuthority ())))
+	    && ((url1.getHost () == null && url2.getHost () == null)
+		|| (url1.getHost () != null
+			&& url1.getHost ().equals(url2.getHost ())))
+	    && ((url1.getPath () == null && url2.getPath () == null)
+		|| (url1.getPath () != null
+			&& url1.getPath ().equals (url2.getPath ())))
+	    && ((url1.getQuery () == null && url2.getQuery () == null)
+                || (url1.getQuery () != null
+			&& url1.getQuery ().equals(url2.getQuery ())))
+	    && ((url1.getRef () == null && url2.getRef () == null)
+		|| (url1.getRef () != null
+			&& url1.getRef ().equals(url2.getRef ()))));
   }
 
   /**
@@ -244,9 +266,12 @@
    * @exception UnknownHostException If an unknown host is found
    */
   protected boolean hostsEqual (URL url1, URL url2)
+    throws UnknownHostException
   {
-    // FIXME: implement this
-    return false;
+    InetAddress addr1 = InetAddress.getByName (url1.getHost ());
+    InetAddress addr2 = InetAddress.getByName (url2.getHost ());
+
+    return addr1.equals (addr2);
   }
 
   /**
@@ -285,8 +310,10 @@
    */
   protected int hashCode (URL url)
   {
-    // FIXME: implement this
-    return 0;
+    return url.getProtocol ().hashCode () +
+           ((url.getHost () == null) ? 0 : url.getHost ().hashCode ()) +
+	   url.getFile ().hashCode() +
+	   url.getPort ();
   }
 
   /**
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.48
diff -u -r1.48 natPlainDatagramSocketImpl.cc
--- java/net/natPlainDatagramSocketImpl.cc	25 Sep 2002 17:14:09 -0000	1.48
+++ java/net/natPlainDatagramSocketImpl.cc	10 Oct 2002 16:18:05 -0000
@@ -283,15 +283,15 @@
 java::net::PlainDatagramSocketImpl::connect (java::net::InetAddress *addr,
 		                             jint  port)
 { 
-  throw new ::java::lang::InternalError (
-    JvNewStringLatin1 ("PlainDatagramSocketImpl::connect: not implemented yet"));
+  throw new ::java::lang::InternalError ( JvNewStringLatin1 (
+	    "PlainDatagramSocketImpl::connect: not implemented yet"));
 }
 
 void
 java::net::PlainDatagramSocketImpl::disconnect ()
 {
-  throw new ::java::lang::InternalError (
-    JvNewStringLatin1 ("PlainDatagramSocketImpl::disconnect: not implemented yet"));
+  throw new ::java::lang::InternalError ( JvNewStringLatin1 (
+	    "PlainDatagramSocketImpl::disconnect: not implemented yet"));
 }
 
 jint

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]