hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Foley (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HADOOP-7342) Add an utility API in FileUtil for JDK File.list
Date Wed, 01 Jun 2011 18:19:47 GMT

    [ https://issues.apache.org/jira/browse/HADOOP-7342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13042338#comment-13042338
] 

Matt Foley commented on HADOOP-7342:
------------------------------------

Cos, the reason I support this new utility api, is that Hadoop is full of constructs like
{code}
// in context of a "throws IOException" or try/catch IOE:
File[] files = dir.list();
if (files.length > 0) {...}
{code}

This code handles empty and non-empty directory lists, and is ready to handle IOExceptions.
 Unfortunately, the posix-style File.list() api returns null when it would reasonably be expected
to throw IOException, causing NPE on the .length method call, which as a run-time exception
isn't typically even looked for.

Rather than inject null-checking code with a conditional throw statement into every place
like this, Bharath has suggested calling this new FileUtil method.  Developers can still use
the JDK method when the null return on IOE is desirable.  I think this is a good idea.

> Add an utility API in FileUtil for JDK File.list
> ------------------------------------------------
>
>                 Key: HADOOP-7342
>                 URL: https://issues.apache.org/jira/browse/HADOOP-7342
>             Project: Hadoop Common
>          Issue Type: Bug
>    Affects Versions: 0.23.0
>            Reporter: Bharath Mundlapudi
>            Assignee: Bharath Mundlapudi
>            Priority: Minor
>             Fix For: 0.23.0
>
>         Attachments: HADOOP-7342-1.patch
>
>
> Java File.list API can return null when disk is bad or directory is not a directory.
This utility API in FileUtil will throw an exception when this happens rather than returning
null. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message