Parameter 'directory' is not a directory for a parameter which is a directory
Asked Answered
C

2

6

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
Changchangaris answered 16/7, 2015 at 23:38 Comment(9)
From File.isDirectory() javadoc, true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise. Since you're using a relative path, it's possibly resolved to a non-existing location. Can you print the path and see if it exists?Livre
In FileUtils.validateListFilesParameters add this line 'System.out.println(directory.getCanonicalPath());' before if (!directory.isDirectory())and see where is this pointing to.Squilgee
@Livre yes I did, I edited my question above under EDIT, it prints out relative path, but I don't understand how this could be a problem.Changchangaris
@Squilgee I'm using FileUtils as a maven dependency, I won't be able to add code into itChangchangaris
put a debug point there and when it stops there at that to watch in eclipse. Only reason it is failing is that at that point is not a directory.Squilgee
Oh wow, I just did what you suggested and I see for 'directory' path gets 'src/test/resources/input_graph' I don't even have this path in my top level. No idea where this is coming from??Changchangaris
Did you ever resolve this? And if so what was the issue? I'm facing a similar problem.Talipes
I got this error when I create a drawable directory with wrong nameCoccyx
Does this answer your question? java.lang.IllegalArgumentException: Parameter 'directory' is not a directory in androidSumac
R
0

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.

Ratline answered 20/12, 2018 at 15:0 Comment(0)
H
-1

Error is thrown if paths cannot be reached

The file paths that you show do not tell where you try to run the code. If you are in your workspace, but you want to run it on a server, and the paths are meant to be on the server, see as follows:

I saw during debugging in the error logs of the console output of my own project that the code tried to get the data from my workspace. While coding, I thought that it would reach the files on the production server, but it did not.

Exception in thread "my_project" java.lang.IllegalArgumentException: Parameter 'directory' is not a directory
        at org.apache.commons.io.FileUtils.validateListFilesParameters(FileUtils.java:545)
        at org.apache.commons.io.FileUtils.listFiles(FileUtils.java:521)
        at org.apache.commons.io.FileUtils.listFiles(FileUtils.java:691)

With the needed file copied to my workspace and the right path in the code, the error was gone since it found the directory.

In my program, my working directory was the repository from where I ran the code. I had to pull the repository on the server to run it with the working directory on the server, so that it could find the production directory for the input files.

Heuristic answered 18/1, 2023 at 2:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.