From e1caed898803653c0c8183eaab732e52b32dd501 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Mon, 21 Oct 2002 04:53:50 +0000 Subject: 2002-10-11 Michael Koch * 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. From-SVN: r58345 --- libjava/java/net/URL.java | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) (limited to 'libjava/java/net/URL.java') diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java index d93dbfb..b485c51 100644 --- a/libjava/java/net/URL.java +++ b/libjava/java/net/URL.java @@ -98,14 +98,9 @@ public final class URL implements Serializable 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 @@ public final class URL implements Serializable 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 @@ public final class URL implements Serializable 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 @@ public final class URL implements Serializable 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); } /** -- cgit v1.1