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

Deprecate Runtime.exec methods with a single string command line argument

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 18
    • core-libs
    • None
    • source
    • minimal
    • Hide
      The methods are only being deprecated, not removed.
      The only source change will be the deprecation warnings.
      Show
      The methods are only being deprecated, not removed. The only source change will be the deprecation warnings.
    • Java API
    • SE

      Summary

      The java.lang.Runtime.exec methods taking a single string as a command line are deprecated. The corresponding methods that take an array of strings should be used instead.

      Problem

      The three java.lang.Runtime.exec methods that tokenize a command line to produce an array of string arguments are easily misused, sometimes with erroneous results. For example, on some operating systems, spaces are supported in filenames and are in common use.

      The tokenization uses only whitespace characters, ignoring quote characters. It is error prone because quotes may appear in the string but are ignored. The implementation (on Windows) includes a heuristic for the executable argument that tries to re-parse the command line respecting quotes but it is undocumented.

      Solution

      Deprecate the three methods and recommend using the corresponding Runtime.exec(String[] cmdarray), Runtime.exec(String[] cmdarray, String[] envp), Runtime.exec(String[] cmdarray, String[] envp, File dir) methods or java.lang.ProcessBuilder.

      Specification

           * ...
           * @deprecated This method is error-prone and should not be used, the corresponding method
           * {@link #exec(String[])} or {@link ProcessBuilder} should be used instead.
           * The command string is broken into tokens using only whitespace characters.
           * For an argument with an embedded space, such as a filename, this can cause problems
           * as the token does not include the full filename.
           * ...
      
          @Deprecated(since="18")
          public Process exec(String command) throws IOException {...}
      
           *...
           * @deprecated This method is error-prone and should not be used, the corresponding method
           * {@link #exec(String[], String[])} or {@link ProcessBuilder} should be used instead.
           * The command string is broken into tokens using only whitespace characters.
           * For an argument with an embedded space, such as a filename, this can cause problems
           * as the token does not include the full filename.
           *...
      
          @Deprecated(since="18")
          public Process exec(String command, String[] envp) throws IOException {...}
      
           *...
           * @deprecated This method is error-prone and should not be used, the corresponding method
           * {@link #exec(String[], String[], File)} or {@link ProcessBuilder} should be used instead.
           * The command string is broken into tokens using only whitespace characters.
           * For an argument with an embedded space, such as a filename, this can cause problems
           * as the token does not include the full filename.
           *...
      
          @Deprecated(since="18")
          public Process exec(String command, String[] envp, File dir) {...}
      

            rriggs Roger Riggs
            rriggs Roger Riggs
            Alan Bateman, Brian Burkhalter, Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: