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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 7u21, 8
    • core-libs
    • None
    • b102
    • x86
    • windows

        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)

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

                Created:
                Updated:
                Resolved: