0

In the following method a part of my code is reading a list of xml files from a folder and returns the list of files. Everything works fine in eclipse but while buillding the same on jenkins, it is failing?

code snippet:

public List<File> getFileList(String dir) {

        File folder = new File(dir);

        List<File> FileList = new ArrayList<File>();

        for (File file : folder.listFiles()) {

            if (file.exists()
                    && file.getName().substring(file.getName().lastIndexOf('.') + 1).contentEquals("xml")) {

                FileList .add(file);
            }
        }
        return xmlFileList;
    }

error on jenkins build, it says null pointer exception

java.lang.NullPointerException
at com.akash.anand.executive.MyClass$FileReader.getFileList(MyClass.java:218)

1 Answers1

0

The dir variable you are passing to getFileList, does it point to a hardcoded path? This might not be available in the Jenkins system.

Since it is a NullPointerException i presume the line File folder = new File(dir); is throwing null pointer as value of dir is itself null. print the dir variable prior to initialising folder object.

Utsav Saha
  • 13
  • 6