src/java.base/share/classes/java/net/URL.java
changeset 55711 0c143aaa2c99
parent 54696 0907dce4b90e
child 57956 e0b8b019d2f5
equal deleted inserted replaced
55710:18130ed28231 55711:0c143aaa2c99
    43 import java.util.ServiceConfigurationError;
    43 import java.util.ServiceConfigurationError;
    44 import java.util.ServiceLoader;
    44 import java.util.ServiceLoader;
    45 
    45 
    46 import jdk.internal.access.JavaNetURLAccess;
    46 import jdk.internal.access.JavaNetURLAccess;
    47 import jdk.internal.access.SharedSecrets;
    47 import jdk.internal.access.SharedSecrets;
       
    48 import sun.net.util.IPAddressUtil;
    48 import sun.security.util.SecurityConstants;
    49 import sun.security.util.SecurityConstants;
    49 import sun.security.action.GetPropertyAction;
    50 import sun.security.action.GetPropertyAction;
    50 
    51 
    51 /**
    52 /**
    52  * Class {@code URL} represents a Uniform Resource
    53  * Class {@code URL} represents a Uniform Resource
   464         } else {
   465         } else {
   465             this.path = file;
   466             this.path = file;
   466             this.file = path;
   467             this.file = path;
   467         }
   468         }
   468 
   469 
   469         // Note: we don't do validation of the URL here. Too risky to change
   470         // Note: we don't do full validation of the URL here. Too risky to change
   470         // right now, but worth considering for future reference. -br
   471         // right now, but worth considering for future reference. -br
   471         if (handler == null &&
   472         if (handler == null &&
   472             (handler = getURLStreamHandler(protocol)) == null) {
   473             (handler = getURLStreamHandler(protocol)) == null) {
   473             throw new MalformedURLException("unknown protocol: " + protocol);
   474             throw new MalformedURLException("unknown protocol: " + protocol);
   474         }
   475         }
   475         this.handler = handler;
   476         this.handler = handler;
       
   477         if (host != null && isBuiltinStreamHandler(handler)) {
       
   478             String s = IPAddressUtil.checkExternalForm(this);
       
   479             if (s != null) {
       
   480                 throw new MalformedURLException(s);
       
   481             }
       
   482         }
   476     }
   483     }
   477 
   484 
   478     /**
   485     /**
   479      * Creates a {@code URL} object from the {@code String}
   486      * Creates a {@code URL} object from the {@code String}
   480      * representation.
   487      * representation.
  1036      *
  1043      *
  1037      * @return    a URI instance equivalent to this URL.
  1044      * @return    a URI instance equivalent to this URL.
  1038      * @since 1.5
  1045      * @since 1.5
  1039      */
  1046      */
  1040     public URI toURI() throws URISyntaxException {
  1047     public URI toURI() throws URISyntaxException {
  1041         return new URI (toString());
  1048         URI uri = new URI(toString());
       
  1049         if (authority != null && isBuiltinStreamHandler(handler)) {
       
  1050             String s = IPAddressUtil.checkAuthority(this);
       
  1051             if (s != null) throw new URISyntaxException(authority, s);
       
  1052         }
       
  1053         return uri;
  1042     }
  1054     }
  1043 
  1055 
  1044     /**
  1056     /**
  1045      * Returns a {@link java.net.URLConnection URLConnection} instance that
  1057      * Returns a {@link java.net.URLConnection URLConnection} instance that
  1046      * represents a connection to the remote object referred to by the
  1058      * represents a connection to the remote object referred to by the
  1633         replacementURL.setSerializedHashCode(tempState.getHashCode());
  1645         replacementURL.setSerializedHashCode(tempState.getHashCode());
  1634         resetState();
  1646         resetState();
  1635         return replacementURL;
  1647         return replacementURL;
  1636     }
  1648     }
  1637 
  1649 
       
  1650     boolean isBuiltinStreamHandler(URLStreamHandler handler) {
       
  1651        return isBuiltinStreamHandler(handler.getClass().getName());
       
  1652     }
       
  1653 
  1638     private boolean isBuiltinStreamHandler(String handlerClassName) {
  1654     private boolean isBuiltinStreamHandler(String handlerClassName) {
  1639         return (handlerClassName.startsWith(BUILTIN_HANDLERS_PREFIX));
  1655         return (handlerClassName.startsWith(BUILTIN_HANDLERS_PREFIX));
  1640     }
  1656     }
  1641 
  1657 
  1642     private void resetState() {
  1658     private void resetState() {