Code Review 6977851: NPE from FileURLConnection.connect
Chris Hegarty
chris.hegarty at oracle.com
Mon Aug 23 10:22:55 PDT 2010
Michael McMahon wrote:
> Chris Hegarty wrote:
>> Michael,
>>
>> The file handler can fail with NPE in cases where permission is denied
>> to the directory. Small change, throw FileNotFoundException where a
>> directory listing is not available.
>>
>> Webrev:
>> http://cr.openjdk.java.net/~chegar/6977851/webrev.00/webrev/
>>
>> Thanks,
>> -Chris.
> One minor comment, and maybe it's not worth the hassle. But, when
> file.list() returns null, you could call file.exists() and then use the
> result of that to customise the exception text.
> false ==> new FileNotFoundException (filename);
> true ==> new FileNotFoundException(filename + " exists, but is not
> accessible");
I agree, a more descriptive message is always a good thing. Actually, we
don't even need to call exists because isDirectory ( called a few lines
before ) will only return true if the file denoted by the abstract
pathname exists and is a directory; so we know already that it must exist.
I wonder what other issues there may be that would cause list to return
null? Actually, your extended message description seem generic enough to
cover most. I think I'll go with your message.
-Chris.
>
> - Michael
More information about the net-dev
mailing list