jdk/src/java.base/share/classes/java/security/CodeSource.java
changeset 31141 ef5ddf021137
parent 30033 b9c86c17164a
child 31538 0981099a3e54
--- a/jdk/src/java.base/share/classes/java/security/CodeSource.java	Fri Jun 12 14:28:21 2015 +0800
+++ b/jdk/src/java.base/share/classes/java/security/CodeSource.java	Fri Jun 12 12:50:41 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.security.cert.*;
+import sun.net.util.URLUtil;
 
 /**
  *
@@ -73,6 +74,15 @@
     private transient CertificateFactory factory = null;
 
     /**
+     * A String form of the URL for use as a key in HashMaps/Sets. The String
+     * form should be behave in the same manner as the URL when compared for
+     * equality in a HashMap/Set, except that no nameservice lookup is done
+     * on the hostname (only string comparison), and the fragment is not
+     * considered.
+     */
+    private transient String locationNoFragString;
+
+    /**
      * Constructs a CodeSource and associates it with the specified
      * location and set of certificates.
      *
@@ -83,6 +93,9 @@
      */
     public CodeSource(URL url, java.security.cert.Certificate certs[]) {
         this.location = url;
+        if (url != null) {
+            this.locationNoFragString = URLUtil.urlNoFragString(url);
+        }
 
         // Copy the supplied certs
         if (certs != null) {
@@ -102,6 +115,9 @@
      */
     public CodeSource(URL url, CodeSigner[] signers) {
         this.location = url;
+        if (url != null) {
+            this.locationNoFragString = URLUtil.urlNoFragString(url);
+        }
 
         // Copy the supplied signers
         if (signers != null) {
@@ -169,6 +185,13 @@
     }
 
     /**
+     * Returns a String form of the URL for use as a key in HashMaps/Sets.
+     */
+    String getLocationNoFragString() {
+        return locationNoFragString;
+    }
+
+    /**
      * Returns the certificates associated with this CodeSource.
      * <p>
      * If this CodeSource object was created using the
@@ -588,6 +611,10 @@
         } catch (IOException ioe) {
             // no signers present
         }
+
+        if (location != null) {
+            locationNoFragString = URLUtil.urlNoFragString(location);
+        }
     }
 
     /*