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

(process) ProcessBuilder.directory() returns null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp



      Name: gm110360 Date: 04/29/2004


      FULL PRODUCT VERSION :
      java full version "1.5.0-beta-b32c"

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      ProcessBuilder.directory() should always return a File, because the default for the working directory is the working directory of the current JVM (process?.) The system property user.dir is not set, but this should not matter.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the following code in a test case. the result is that "dir is null" is printed. Also, ProcessBuilder.start() will fail (because of this? unsure, because error=2 is very undescriptive.)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      pb.directory should give a valid value, which is the File representing the current directory of the actual JVM. See the class discription JavaDoc.
      ACTUAL -
      The output is:
      dir is null
      <a bunch of env variables here>
      java.io.IOException: CreateProcess: dir error=2
              at java.lang.ProcessImpl.create(Native Method)
              at java.lang.ProcessImpl.<init>(Unknown Source)
              at java.lang.ProcessImpl.start(Unknown Source)
              at java.lang.ProcessBuilder.start(Unknown Source)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      try
      {
      ProcessBuilder pb = new ProcessBuilder("dir");
      if (pb.directory()== null)
      System.out.println("dir is null");
      else
      System.out.println(pb.directory().getAbsolutePath());
      if (pb.environment()== null)
      System.out.println("env is null");
      else
      for(String key : pb.environment().keySet())
      {
      System.out.println(key+" "+pb.environment().get(key));
      }
      Process proc = pb.start();
      } catch (IOException ie){
      ie.printStackTrace();
      //TODO: do something here
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can always do:
      pb.directory(new File("."));
      (Incident Review ID: 260397)
      ======================================================================

            martin Martin Buchholz
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: