[ 
https://issues.apache.org/jira/browse/MAHOUT-582?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sean Owen resolved MAHOUT-582.
------------------------------

       Resolution: Fixed
    Fix Version/s: 0.5
         Assignee: Sean Owen

Great, thanks. Committed.

> Add check for empty files passed to FileDataModel constructor in order to 
> generate a better error message.
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: MAHOUT-582
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-582
>             Project: Mahout
>          Issue Type: Improvement
>    Affects Versions: 0.5
>         Environment: Environment neutral.
>            Reporter: Donald Bleyl
>            Assignee: Sean Owen
>            Priority: Minor
>             Fix For: 0.5
>
>         Attachments: emptyfile.patch
>
>   Original Estimate: 0.08h
>  Remaining Estimate: 0.08h
>
> The FileDataModel constructor checks for a null arg for dataFile, and a few 
> other conditions, but not for an empty file.  If an empty file is passed in, 
> it triggers a NullPointerException when the first line is evaluated.
> For an empty file, an NPE is raised when firstLine.length() is called:
>     FileLineIterator iterator = new FileLineIterator(dataFile, false);
>     String firstLine = iterator.peek();
>     while ((firstLine.length() == 0) || (firstLine.charAt(0) == 
> COMMENT_CHAR)) {
> Proposed fix is to add a check for a zero-length file:
>     Preconditions.checkArgument(dataFile != null, "dataFile is null");
>     if (!dataFile.exists() || dataFile.isDirectory()) {
>       throw new FileNotFoundException(dataFile.toString());
>     }
>     Preconditions.checkArgument(dataFile.length() > 0L, "dataFile is empty");
> A unit test has been included in the patch.

-- 
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