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

Todd Lipcon commented on HADOOP-5700:
-------------------------------------

bq. In your case, if getPathNames() returned 'new String[0];' rather than null, 
would the it work fine? (i.e. namenode.getFileInfo() behaves as though a 
non-existent path was queried). 

Well, I would actually prefer either an IllegalArgumentException or an 
IOException that explicitly says ("Argument to getFileInfo should be an 
absolute path") rather than a vanilla FileNotFound exception. This makes it 
clear to the user-developer that they are misusing the API rather than just 
looking for a nonexistent file.

bq. But that still leaves the problem with namenode.getFileInfo(null). 

I think if people pass a null into a function they should expect it to break. 
That's an easy thing to diagnose from the user-developer perspective, whereas 
missing initial '/' is a bit trickier.

I'd love to include something like the google Preconditions class for cases 
like this. It cuts down on code cruft and makes it clear what is going on:

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Preconditions.html

> INode.getPathComponents throws NPE when given a non-absolute path
> -----------------------------------------------------------------
>
>                 Key: HADOOP-5700
>                 URL: https://issues.apache.org/jira/browse/HADOOP-5700
>             Project: Hadoop Core
>          Issue Type: Bug
>          Components: dfs
>            Reporter: Todd Lipcon
>            Assignee: Todd Lipcon
>            Priority: Minor
>             Fix For: 0.21.0
>
>         Attachments: HADOOP-5700.txt
>
>
> If you pass a path that doesn't start with '/' to INode.getPathComponents, it 
> throws a NullPointerException. Instead it should throw 
> IllegalArgumentException to make it clear that absolute paths are required in 
> this code.
> The attached patch fixes this, clarifies, the javadoc, and adds a test case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to