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

FTP URLs in URLClassLoader appear to be broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.1, 1.3.0
    • core-libs
    • generic
    • generic

      Name: mc57594 Date: 11/04/99

      Attempting to use an FTP URL in a URLClassLoader with username:password syntax *appears* to be broken; example (username and password changed to protect the innocent :) ):

      import java.net.URL;
      import java.net.URLClassLoader;

      import java.io.*;

      public class FTPURLClient
      {
          /**
           * Attempt to instantiate an instance of the class
           * com.javageeks.util.Hello, found only on the javageeks.com
           * FTP server in the "examples" directory.
           */
          public static void main(String[] args)
              throws Exception
          {
              URL[] urlArray =
              {
                  new URL("ftp", "reader:###@###.###",
                          "/examples/")
              };

              URLClassLoader ucl = new URLClassLoader(urlArray);
              Object obj =
                  ucl.loadClass("Hello").newInstance();
                  
              // Hello should print "Hello from JavaGeeks.com!" to the
              // System.out stream
          }
      }

      Instead, the output is:

      E:\Projects\Books\SSJ\cd\Src\Chap02>java FTPURLClient
      Exception in thread "main" java.lang.ClassNotFoundException: Hello
              at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:237)
              at FTPURLClient.main(FTPURLClient.java:24)

      If a trailing "/" is appended to "/examples" in the file portion of the URL (examples is a directory which contains the Hello.class file), the output is:

      E:\Projects\Books\SSJ\cd\Src\Chap02>java FTPURLClient
      Exception in thread "main" java.lang.IllegalArgumentException: invalid port rang
      e: ###@###.###
              at java.net.SocketPermission.init(SocketPermission.java:338)
              at java.net.SocketPermission.<init>(SocketPermission.java:206)
              at java.net.URLClassLoader.getPermissions(URLClassLoader.java:417)
              at java.security.SecureClassLoader.getProtectionDomain(SecureClassLoader
      .java:145)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:10
      1)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
              at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:237)
              at FTPURLClient.main(FTPURLClient.java:24)
      (Review ID: 84958)
      ======================================================================

      From: chamness <###@###.###>
      To: ###@###.### <###@###.###>
      Date: Tuesday, June 29, 1999 8:07 PM
      Subject: Re: (Review ID: 84958) FTP URLs in URLClassLoader appear to be
      broken

      >Ted,
      >Before we start debugging the problem, can you try something?
      >It looks like you want to load the class, com.javageeks.util.Hello.
      >But in your application you wrote:
      > ucl.loadClass("Hello").newInstance();
      >
      >Can you try:
      > ucl.loadClass("com.javageeks.util.Hello").newInstance();
      >I assume that you have the class Hello in the appropriate
      >subdirectory.
      >
      >Mark
      ========================================
      From: "Ted Neward" <###@###.###>
      To: "chamness"
      Subject: Re: (Review ID: 84958) FTP URLs in URLClassLoader appear to be broken
      Date: Tue, 29 Jun 1999 23:21:59 -0700

      Actually, I've tried both approaches; I shortened it to just "Hello" in
      order to eliminate the possibility that the FTP-URLClassLoader thing didn't
      handle package-names-as-directories well. The code actually comes from a
      chapter I'm writing on ClassLoaders for a book that's coming out soon. The
      original intent was to download the fully package-qualified verison of
      Hello, but now I'll settle for a plain 'ol unnamed-package version. :)

      I've got two FTP servers I've tested this approach against--an NT4.0/IIS FTP
      web server, and a Linux RedHat 5.2 FTP server, both as anonymous and using
      the username-password approach. I freely admit I'm not a system admin, but
      I'm pretty sure I got the FTP parts right--I can FTP in using the userid and
      password using ye olde standard FTP command.

      Anything else I can offer to help?

      Ted Neward
      Patterns/C++/Java/CORBA/EJB/COM-DCOM spoken here
      http://www.javageeks.com/~tneward
       "I don't even speak for myself; my wife won't let me." --Me


      Name: krC82822 Date: 12/19/2000


      orig synopsis: "URL doesn't support the same syntax with ftp and http"

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

      Since version 1.2, java.net.URL has supported the following syntax:

      ftp://username:password@host/path/file

      but not:

      http://username:password@host/path/file

      It would be nice, if version 1.4 would support this syntax for
      both ftp and http.
      (Review ID: 110326)
      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: