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

FileURLConnection is always connected when using UNC pathnames

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • generic
    • generic



      Name: boT120536 Date: 01/03/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      URL.openConnection() typically returns an unconnected URLConnection, on which
      one can set request properties, if-modified-since (which FileURLConnection
      should support also but does not), or other pre-connection properties. This is
      useful, because it preserves the transparency of the URLConnection, allowing
      one to set up the URLConnection is a generic way before connecting.

      However, sun.net.www.protocol.file.Handler violates this by calling connect on
      the URLConnection in the case of a UNC Path (a fix to 4180841). This means
      that code now has to be changed to special case FileURLConnection, as there is
      no way to check if a URLConnection is already connected.

      Below is a program that demonstrates this. It should configure the
      URLConnection prior to connecting and never actually connect to the specified
      location, but if the URL includes a UNC pathname, it will throw an
      IllegalAccessException at the line that says "conn.setRequestProperty(...)",
      because line 72 of sun.net.www.protocol.file.Handler.java connects to the remote
      resource.

      import java.io.*;
      import java.net.*;

      public class URLFilePrinter
      {
          public static void main( String[] args )
          {
              // Assume first argument is a URL
              try
              {
                  URL location = new URL( args[0] );

                  // This line should just create the URLConnection object,
                  // but if it is a UNC path name, then the connection object
                  // will have become connected due to line 72 of
                  // sun.net.www.protocol.file.Handler.java
                  URLConnection conn = location.openConnection();

                  // The following line should operate fine, but if it is
                  // a UNC pathname, it will throw an IllegalAccessException
                  conn.setRequestProperty( "User-Agent", "MyUserAgent" );
              }
              catch( Exception ex )
              {
                  System.out.println( "Exiting with exception: " + ex );
              }
          }
      }
      (Review ID: 114397)
      ======================================================================

            alanb Alan Bateman
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: