Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179883

listFiles() method execution always returns NULL when run from command line

XMLWordPrintable

    • generic
    • windows

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10

      A DESCRIPTION OF THE PROBLEM :
      1. I have created a small application that recurses through a given directory and prints out all the file names.

      2. When I run this application from command line using java command (I have configured my environment variables and classpath correctly), my #listFiles() method invocation always returns NULL.

      3. The same application, when built and run from Eclipse IDE, the files names are printed normally and no issues.

      4. My eclipse run normally and I don't have to provide any special privileges to execute my executable application.

      5. The problem seems to be coming from isInvalid() method in java.io.File. It is always returning Invalid for indexOf('\u0000') for path.

      Could you kindly comment?

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      // Method

      public static LinkedList<File> checkFile(String path, LinkedList<File> result) Throws IOException, SecurityException{
          File root = new File(path);
          File[] list = root.listFiles();

          if (list == null)
              return result;

          for (File f : list) {
              if (f.isDirectory()) {
                  checkFile(f.getAbsolutePath(), result);
              } else {
                      result.add(f.getAbsoluteFile());
              }
          }
          return result;
      }

      // Main Def

      public static void main(String[] args) throws IOException {

          if (args.length == 0 || args[0] == null){
              System.out.println("please specify path to the project's work folder");
              return;
          }

          String folderPath = (String) args[0];
          LinkedList<File> result = new LinkedList<>();

          result = checkFile(folderPath, result);
          long startTime = System.currentTimeMillis();
          for (File file : result) {
              System.out.println(file.getName());
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A list of files depending on the validity of the path provided
      ACTUAL -
      Exists application since no file list can be checked

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      When I run it from Eclipse IDE, as a project, it runs correctly.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: