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

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

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95

      Description



      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"
      says:
      file

         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
         file.

         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:
                http://www.ncsa.uiuc.edu/demoweb/url-primer.html
      (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.
           Parameters:
               spec - the String to parse as a URL.
           Throws:
               MalformedURLException - If the string specifies an unknown protocol.
      "

      The example:
      --------------------------------8-<---------------------------
      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) {
            System.out.println("OKAY");
            return;
          }
        }
      }

      --------------------------------8-<---------------------------
      java full version "JDK-1.2fcs-K"
      Output:
      No MalformedURLException

         
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: