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

ProcessBuilder removes double-quotes from arguments under Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 8u51
    • core-libs
    • x86
    • windows_8

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      Using ProcessBuilder to invoke a process under Windows, arguments containing double-quote characters are not handled properly. The quotes are omitted from the strings received by the Windows process. E.g. the string "a\"b" passed to ProcessBuilder is seen as "ab" by the process.

      If the quote is explicitly escaped in the string passed to ProcessBuilder, it will be seen by the process. But that should not be the responsibility of the programmer and breaks multi-platform compatibility. (E.g. "a\\\"b" -> "ab" in the called process.)

      Arguments should be preprocessed by the library under Windows to convert contained '"' to "\\\"".

      ADDITIONAL REGRESSION INFORMATION:
      Behaves the same under Windows Vista.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run my test probram, below.

      javac WindowsProcessBuilderBug.java
      java WindowsProcessBuilderBug



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Arguments containing double-quotes should be received intact by the called process.
      ACTUAL -
      Arguments containing double-quotes are not received intact by the called process.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      WindowsProcessBuilderBug.java:
      ========================================
      import java.io.IOException;
      import java.util.Arrays;

      class WindowsProcessBuilderBug {

          public static void main(String[] args) throws IOException,
                  InterruptedException {
              if (args.length > 0) {

                  // If called with arguments, print the arguments.
                  System.out.println(Arrays.toString(args));

              } else {

                  // If called with no arguments, test passing arguments
                  // containing double quotes.
                  System.out.println("Calling with arguments " +
                      "noquotes, \"quoted\", middle\"quote" +
                      " does not work.");
                  new ProcessBuilder("java", "WindowsProcessBuilderBug",
                          "noquotes", "\"quoted\"", "middle\"quote").
                          inheritIO().start().waitFor();

                  // The following code shows that the quotes *can* be passed,
                  // and hints as to the nature of the bug and how ProcessBuilder
                  // can be fixed.
                  System.out.println();
                  System.out.println("Calling with jury-rigged arguments " +
                      "noquotes, \\\"quoted\\\", middle\\\"quote" +
                      " gets the quotes, but is not how it should work.");
                  new ProcessBuilder("java", "WindowsProcessBuilderBug",
                          "noquotes", "\\\"quoted\\\"", "middle\\\"quote").
                          inheritIO().start().waitFor();

              }
          }

      }
      ========================================
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Preprocess argument strings by replacing "\"" > "\\\""

      Attachments

        Activity

          People

            igerasim Ivan Gerasimov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: