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

(process) IOException thrown by ProcessBuilder.start() method is incorrectly encoded

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u21, 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b102
    • CPU:
      x86
    • OS:
      windows

      Backports

        Description

        Only Windows platform is affected.
        The problem can be easily reproduced on non-English Windows (e.g., russian Windows 7 when Cp1251 character page is in use) using following snippet:

        try {
            Runtime.getRuntime().exec("ttttttttt");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        As the result you can see following output with invalid characters:

        java.io.IOException: Cannot run program "ttttttttt": CreateProcess error=2, ?? ??????? ????? ????????? ????
                at java.lang.ProcessBuilder.start(Unknown Source)
                at java.lang.Runtime.exec(Unknown Source)
                at java.lang.Runtime.exec(Unknown Source)
                at java.lang.Runtime.exec(Unknown Source)
                ...
        Caused by: java.io.IOException: CreateProcess error=2, ?? ??????? ????? ????????? ????
                at java.lang.ProcessImpl.create(Native Method)
                at java.lang.ProcessImpl.<init>(Unknown Source)
                at java.lang.ProcessImpl.start(Unknown Source)
                ... 6 more


        Note, that detailed message with correct encoding can be obtained using the following trick:

        new String(ex.getMessage().getBytes("ISO-8859-1"),Charset.defaultCharset().displayName());

        The bug is reside in native part of JDK at jdk\src\windows\native\java\lang\ProcessImpl_md.c
        See "static void win32Error(JNIEnv *env, const char *functionName)" method there.
        This method does not consider character page of underlying system.

        As an example how to correctly process encoding of the error message you can look at
        jdk\src\share\native\common\jni_util.c, method JNIEXPORT void JNICALL JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name, const char *defaultDetail)

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  uta Alexey Utkin (Inactive)
                  Reporter:
                  aburduko Alexander Burdukov
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: