Java – Parameter ‘directory’ is not a directory for a parameter which is a directory

fileutilsiojavaoop

I'm getting a strange error where the parameter I supply to a method complains that it's not a directory but it IS in fact a directory with files in it…I don't understand what's wrong…

Toplevel:

public static File mainSchemaFile = new File("src/test/resources/1040.xsd");
public static File contentDirectory = new File("src/test/resources/input");
public static File outputDirectory = new File("src/test/resources/output");


DecisionTableBuilder builder =constructor.newInstance(log, contentDirectory, outputDirectory);

// Here is where the error occurs
builder.compile(mainSchemaFile);

The class I'm using:

public class DecisionTableBuilder {

   public void compiler(File schemaFile) {
      ...
      // It's complaining about contentDirectory, it goes to FileUtils class for this
      Collection<File> flowchartFiles = FileUtils.listFiles(contentDirectory, mapExtension, true);
      ...
   }
}

Here is the apache FileUtils class:

public class FileUtils {

    private static void validateListFilesParameters(File directory, IOFileFilter fileFilter) {
        if (!directory.isDirectory()) {
            throw new IllegalArgumentException("Parameter 'directory' is not a directory");
        }
        if (fileFilter == null) {
            throw new NullPointerException("Parameter 'fileFilter' is null");
        }
    }

}

Output: Parameter 'directory' is not a directory

Which is the error output I am getting…

Anyone have any idea what is happening here I'm super confused…any help will be greatly appreciated.

EDIT:

In my toplevel I added the following line:

if(contentDirectory.isDirectory()) {
    System.out.println("Content Directory: "+contentDirectory);
}

Output: src/test/resources/input

Best Answer

You're pointing to the file and not a directory in mainSchemaFile variable. Reduce the path to the folder containing 1040.xsd - it should resolve the issue.