Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4175737

java.net.URL should throw MalformedURLException on incorrect FILE:


    • Subcomponent:
    • CPU:
    • OS:


      Name: akC57697 Date: 09/23/98

        The java.net.URL c-tor does not throw MalformedURLException on
        incorrect FILE: requests which use "diskname:" in path.

      The doc of Network Working Group
      Request for Comments: 1630 CERN
      Category - Informational June 1994

                       Universal Resource Identifiers in WWW

                      A Unifying Syntax for the Expression of
                   Names and Addresses of Objects on the Network
                           as used in the World-Wide Web"

         The other URI schemes (except nntp) share the property that they are
         equally valid at any geographical place.

         There is however a real practical requirement to be able to generate
         a URL for an object in a machine's local file system.

         The syntax is similar to the ftp syntax, but in this case the slash
         is used to donate boundaries between directory levels of a
         hierarchical file system is used. The "client" software converts the
         file URL into a file name in the local file name conventions. This
         allows local files to be treated just as network objects without any
         necessity to use a network server for access. This may be used for
         example for defining a user's "home" document in WWW.

         There is clearly a danger of confusion that a link made to a local
         file should be followed by someone on a different system, with
         unexpected and possibly harmful results. Therefore, the convention
         is that even a "file" URL is provided with a host part. This allows
         a client on another system to know that it cannot access the file
         system, or perhaps to use some other local mecahnism to access the

         The special value "localhost" is used in the host field to indicate
         that the filename should really be used on whatever host one is.
         This for example allows links to be made to files which are
         distribted on many machines, or to "your unix local password file"
         subject of course to consistency across the users of the data.

         A void host field is equivalent to "localhost".

      The javadoc:
      More information on the types
      of URLs and their formats can be found at:
      (see above)
      public URL(String spec)
          throws MalformedURLException

           Creates a URL object from the String representation.

           This constructor is equivalent to a call to the two-argument constructor with
           a null first argument.
               spec - the String to parse as a URL.
               MalformedURLException - If the string specifies an unknown protocol.

      The example:
      class Test {
        public static void main(String[] argv) {
          try {
           java.net.URL u = new java.net.URL("file:C:/autoexec.bat");
                                           // Should be "file:///C:/autoexec.bat"
           System.out.println("No MalformedURLException");
          } catch (java.net.MalformedURLException e) {

      java full version "JDK-1.2fcs-K"
      No MalformedURLException



          Issue Links



              • Assignee:
                akuzminorcl Alexander Kuzmin (Inactive)
              • Votes:
                0 Vote for this issue
                0 Start watching this issue


                • Created: