classpath
[Top][All Lists]
Advanced

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

Re: File.list()


From: Michael Koch
Subject: Re: File.list()
Date: Sat, 10 Jan 2004 18:18:00 +0100
User-agent: Mutt/1.3.28i

On Mon, Nov 24, 2003 at 08:44:56PM -0500, David BĂ©langer wrote:
> 
> 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.

Sorry for answering so late.

According to SUNs JDK 1.4.2 online api documentation this method doesnt
throw any exception except SecurityException. Throwing an IOException
would be wrong.

I think the code you marked above is wrong because it hides an error in
listInternal with an empty file list. list(FilenameFilter filter) should
return null.

Just my 2 cents.


Michael




reply via email to

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