If you need any other information please let me know.
Short Version:
This line of code causes a NullPointerException when tested with jUnit 4.12:
File[] files = new File(searchPath).listFiles();
Long version:
First of all, this is the enviroment:
- OS: Win7 Pro (Netbeans runs as Admin)
- IDE: Netbeans 8.0.2
- Build automation tool: Gradle
- Java: JDK 1.8
- Test-Framework: jUnit 4.12
The exception only occurs when i run jUnit-tests. When i build it without any tests, everything works fine and the function listFiles() from File[] files = new File(searchPath).listFiles() doesn't return null.
gradle clean & gradle build -x test & gradle rest:jettyRun 2> test.txt
This is the problem-function, called in the constructor of my class:
/**
 * Scans for JSON files on given path
 * @param searchPath full path given
 * @return String[] with the full paths and names of found files
 */
private String[] scanForJsons(String searchPath){
    System.out.println("search path "+searchPath); // shows D:\..\core\files
    File[] files = new File(searchPath).listFiles(); // problem line, allways returns null
    System.out.print(((files!=null)?"Not null" : "Null"));
    System.out.println("files.length: "+files.length);
    String[] stringArray = new String[files.length];
    for(int i = 0; i < files.length; i++){
        String path = files[i].getName();
        if (path.endsWith(".json")) {
            path = path.substring(0, path.length() - 5);
        }
        stringArray[i] = path;
    }
    return stringArray;
}
 
     
    