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)

          Issue Links

            Activity

            Hide
            uta Alexey Utkin (Inactive) added a comment -
            This bug is a child of [JDK-8001334 - Remove use of JVM_* functions from java.io code] bug. That is the old pain of localized Non-Western Windows:
              Output: IOException: Cannot run program ".\Programi\\": CreateProcess error=2, Íå óäàåòñÿ íàéòè óêàçàííûé ôàéë
            or
              Output: IOException: Cannot run program ".\Programi\\": CreateProcess error=2, ?? ??????? .....
            depends from you default locale for non-Unicode characters.

            The solution is to switch to Unicode API and use UTF-16 to UTF-8 conversion for each [char *] JVM API string parameters.
            That is hard to solve problem locally - it have to be resolved on the library level.
            Show
            uta Alexey Utkin (Inactive) added a comment - This bug is a child of [ JDK-8001334 - Remove use of JVM_* functions from java.io code] bug. That is the old pain of localized Non-Western Windows:   Output: IOException: Cannot run program ".\Programi\\": CreateProcess error=2, Íå óäàåòñÿ íàéòè óêàçàííûé ôàéë or   Output: IOException: Cannot run program ".\Programi\\": CreateProcess error=2, ?? ??????? ..... depends from you default locale for non-Unicode characters. The solution is to switch to Unicode API and use UTF-16 to UTF-8 conversion for each [char *] JVM API string parameters. That is hard to solve problem locally - it have to be resolved on the library level.
            Hide
            uta Alexey Utkin (Inactive) added a comment -
            Workaround solution
                    jdk\src\share\native\common\jni_util.c, method JNIEXPORT void JNICALL JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name, const char *defaultDetail)
            is good only for consistent OS - APP - Default code page configuration. Any Japan language name file in Russian Windows will back the problem.
            Yes, that is better than nothing, but not good.
            Show
            uta Alexey Utkin (Inactive) added a comment - Workaround solution         jdk\src\share\native\common\jni_util.c, method JNIEXPORT void JNICALL JNU_ThrowByNameWithLastError(JNIEnv *env, const char *name, const char *defaultDetail) is good only for consistent OS - APP - Default code page configuration. Any Japan language name file in Russian Windows will back the problem. Yes, that is better than nothing, but not good.
            Hide
            uta Alexey Utkin (Inactive) added a comment -
            Test results for suggested fix and 7u40
            Show
            uta Alexey Utkin (Inactive) added a comment - Test results for suggested fix and 7u40
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/e6aeeec33e53
            User: uta
            Date: 2013-07-19 08:56:21 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/e6aeeec33e53 User: uta Date: 2013-07-19 08:56:21 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/e6aeeec33e53
            User: lana
            Date: 2013-08-06 17:34:56 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/e6aeeec33e53 User: lana Date: 2013-08-06 17:34:56 +0000

              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: