classpath
[Top][All Lists]
Advanced

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

File.list()


From: David Bélanger
Subject: File.list()
Date: Mon, 24 Nov 2003 20:44:56 -0500
User-agent: Mutt/1.3.28i

Hi,

This may be some trace left from a old bug.

File: java/io/File.java.


A long time ago, there was a bug with listInternals as it was
not returning an empty array for "no files".  This has been
fixed since then and listInternals returns only NULL on error.
If there are no files, it correctly returns a String array
of length 0.

The current implementation of Filelists is as follows:

---------
  public String[] list (FilenameFilter filter)
  {
    checkRead ();

    // Get the list of files
    String list_path = PlatformHelper.removeTailSeparator(path);
    File dir = new File(list_path);

    if (! dir.exists() || ! dir.isDirectory() ) return null;
    
    String files[] = listInternal(list_path);
    
--> if (files == null)
-->   return new String[0];
    if (filter == null)
      return files;
------------

Note: From the current implementation of listInternal, it will return NULL
      only on error, and it will correctly return "new String[0]" if
      the directory is empty.  (I checked with gdb to make sure).

So, I suggest something like:
    if (files == null) {
      throw new IOException("Unknown IO Exception");
    }
I am assuming some JCL_* functions set exceptions on errors (did not study
them) but this may get other exceptional cases.


Let me know if it makes sense.


David


---

David Bélanger
Graduate Student
School of Computer Science
McGill University
Office: MC226

Web page:   http://www.cs.mcgill.ca/~dbelan2/
Public key: http://www.cs.mcgill.ca/~dbelan2/public_key.txt





reply via email to

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