[kaffe] CVS kaffe (dalibor): Fixed CodeSource for policy files

Kaffe CVS cvs-commits at kaffe.org
Fri Mar 12 10:54:46 PST 2004


PatchSet 4514 
Date: 2004/03/12 18:24:36
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Fixed CodeSource for policy files

2004-03-12  Casey Marshall <rsdio at metastatic.org>

        * libraries/javalib/java/security/CodeSource.java
        (location): marked final.
        (certificates): marked final.
        (<init>): clone the certificate array.
        (getCertificates): clone the certificate array.
        (equals): handle null components.
        (hashCode): handle null components.
        (toString): handle null components.
        (implies): don't check SocketPermission if the host field of
        location is empty.

Members: 
	ChangeLog:1.2093->1.2094 
	libraries/javalib/java/security/CodeSource.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2093 kaffe/ChangeLog:1.2094
--- kaffe/ChangeLog:1.2093	Fri Mar 12 18:04:23 2004
+++ kaffe/ChangeLog	Fri Mar 12 18:24:36 2004
@@ -1,3 +1,16 @@
+2004-03-12  Casey Marshall <rsdio at metastatic.org>
+
+        * libraries/javalib/java/security/CodeSource.java
+        (location): marked final.
+        (certificates): marked final.
+        (<init>): clone the certificate array.
+        (getCertificates): clone the certificate array.
+        (equals): handle null components.
+        (hashCode): handle null components.
+        (toString): handle null components.
+        (implies): don't check SocketPermission if the host field of
+        `location' is empty.
+
 2004-03-12  Jon Nall <nall at themountaingoats.net>
 
 	* kaffe/jvmpi/jvmpi_kaffe.c:
Index: kaffe/libraries/javalib/java/security/CodeSource.java
diff -u kaffe/libraries/javalib/java/security/CodeSource.java:1.4 kaffe/libraries/javalib/java/security/CodeSource.java:1.5
--- kaffe/libraries/javalib/java/security/CodeSource.java:1.4	Sun May 18 16:44:56 2003
+++ kaffe/libraries/javalib/java/security/CodeSource.java	Fri Mar 12 18:24:37 2004
@@ -5,7 +5,7 @@
  * Copyright (c) 1999
  *	Archie L. Cobbs.  All rights reserved.
  * Copyright (c) 1999
- *	Transvirtual Technologies, Inc.  All rights reserved.
+ *	Transvirtual Technologies, Inc.	 All rights reserved.
  *
  * See the file "license.terms" for information on usage and redistribution
  * of this file.
@@ -24,12 +24,16 @@
 
 public class CodeSource implements Serializable {
 
-    private URL location;
-    private java.security.cert.Certificate [] certificates;
+    private final URL location;
+    private final java.security.cert.Certificate [] certificates;
 
-    public CodeSource(URL location, java.security.cert.Certificate[] certificates) {
+    public CodeSource(final URL location, final java.security.cert.Certificate[] certificates) {
 	this.location = location;
-	this.certificates = certificates;
+	if (certificates != null) {
+	    this.certificates = (java.security.cert.Certificate[]) certificates.clone();
+	} else {
+	    this.certificates = null;
+	}
     }
 
     public boolean equals(Object obj) {
@@ -42,12 +46,30 @@
 
 	CodeSource that = (CodeSource) obj;
 
-	return getLocation().equals(that.getLocation())
-	    && getCertSet().equals(that.getCertSet());
+	if (location == null) {
+	    if (that.location != null) {
+		return false;
+	    }
+	} else if (!location.equals(that.location)) {
+	    return false;
+	}
+	if (certificates == null) {
+	    if (that.certificates != null) {
+		return false;
+	    }
+	} else {
+	    if (!getCertSet().equals(that.getCertSet())) {
+		return false;
+	    }
+	}
+	return true;
     }
 
     public final java.security.cert.Certificate[] getCertificates() {
-	return certificates;
+	if (certificates == null) {
+	    return null;
+	}
+	return (java.security.cert.Certificate[]) certificates.clone();
     }
 
     private Set getCertSet() {
@@ -59,8 +81,16 @@
     }
 
     public int hashCode() {
-	return getLocation().hashCode()
-	    ^ getCertSet().hashCode();
+	int sum = 0;
+	if (location != null) {
+	    sum += location.hashCode();
+	}
+	if (certificates != null) {
+	    for (int i = 0; i < certificates.length; i++) {
+		sum += certificates[i].hashCode();
+	    }
+	}
+	return sum;
     }
 
     public boolean implies(CodeSource other) {
@@ -99,7 +129,7 @@
 	    }
 
 	    /* Check 3.4 */
-	    if  (getLocation().getHost() != null) {
+	    if	(getLocation().getHost() != null && ! getLocation().getHost().equals("")) {
 		if (! new SocketPermission(getLocation().getHost(), "")
 		    .implies(new SocketPermission(other.getLocation().getHost(), ""))) {
 		    return false;
@@ -151,7 +181,7 @@
     public String toString() {
 	return getClass().getName()
 	    + "[location=" + getLocation()
-	    + ",certificates=" + getCertSet()
+	    + ",certificates=" + (certificates != null ? getCertSet().toString() : "none")
 	    + ']';
     }
 }




More information about the kaffe mailing list