JDK-8016579 : (process) IOException thrown by ProcessBuilder.start() method is incorrectly encoded
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7u21,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86
  • Submitted: 2013-06-13
  • Updated: 2018-09-04
  • Resolved: 2013-07-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u80Fixed 8 b102Fixed
Related Reports
Relates :  
Relates :  
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)

Comments
Test results for suggested fix and 7u40
12-07-2013

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.
01-07-2013

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.
01-07-2013