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
            Priority: Minor


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