|
Adopted your regex fix, in a slightly different form.
On the other hand, I disagree that failure to parse should not return null. This helps us to find Returning null for a non-parsed entry is neither graceful degradation nor a
clear indication of the problem. The API of FTPClient.listFiles() does not mention that it can return null entries, so it is not obvious why there are holes in the returned array and why you run into NPEs. I think you should either return a FTPFile where at least getRawListing() works You raise an interesting point. I still don't agree with it. While I see merit in your claim that
having arrays with null members is not a good thing, there are similar problems also inherent in "incomplete" objects. The uninformed user may just as well stumble on NPEs when dereferencing a non-existent date in a partially complete FTPFile, for example. The null member, while obviously not a perfect solution, does announce itself reasonably loudly, is easily detectable by the user, and that has value. Throwing an exception over the whole list might be too draconian a penalty for one unparsed listing out of a hundred. Thus, the current implementation is a reasonable compromise, I think. Our goal remains to have parsers that handle every conceivable case, even if that is almost Your point about the return value of listFiles() not being documented to warn the user of this An additional point here is backward compatibility. This API is by now several years old.
Much code has been written based on the twin assumptions that: Changing these assumptions to will break too much existing code to be seriously considered as an alternative now. If this was
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
-rwxrwxrwx 1 owner group 257112 Jun 27 0:45 testalbum.zip
drwxrwxrwx 1 owner group 0 Aug 21 2002 testdir
drwxrwxrwx 1 owner group 0 May 28 0:39 tmp
testalbum.zip and tmp will result in null.
I see two problems here:
o the regex matcher will fail if there is only one field wrong. Maybe there
should be a regex call for each field, so could at least fill the correctly
parsed fields.
o in case of a failed match there should not be returned null but rather an
empty FTPFile. There was a real ftp server output line, so no need to have it
nulled. If there is a parse error, it's not the fault of the server but a bug in
the regex.