bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/22778] URLConnection.connect does not work on directories


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/22778] URLConnection.connect does not work on directories
Date: 16 Oct 2005 01:27:09 -0000

With an URL (file protocol) representing a local existing directory, the
connect() method fails with java.io.FileNotFoundException: /tmp/bug/. is a
directory
(tested with kaffe, sablevm and gij 3.4 on Debian GNU/Linux).
gij 3.3 does not fail on connect, but it does if you later try to open an
InputStream from that URL.

On all Sun JVMs I could try (1.3, 1.4 and 1.5), connect() works. Furthermore,
it's possible to read from the connection. There is some difference there. 1.3
prints  html code (like what you'd get from a web directory listing). 1.4 and
1.5 return one line for each file in the directory. I think it would make the
most sense for classpath to behave the same as 1.4 and 1.5.

Here is a minimal testcase:

public class Bug
{
  public static void main(String[] args)
  {
    try {
      java.net.URL dir = new java.io.File(".").toURL();

      java.net.URLConnection con = dir.openConnection();
      // Connect should work on an existing directory
      con.connect();
      System.out.println("OK, content:");

      // Print the stream associated with the URL
      java.io.BufferedReader in = new java.io.BufferedReader
        (new java.io.InputStreamReader(con.getInputStream()));
      String line;
      for (; (line = in.readLine()) != null;)
        System.out.println(line);

    }
    catch(java.io.IOException e) {
      e.printStackTrace();
    }
  }
}


------- Comment #1 from from-classpath at savannah dot gnu dot org  2004-09-09 
12:18 -------
Another patch


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22778





reply via email to

[Prev in Thread] Current Thread [Next in Thread]