Given the following environment:
- Windows 10
- Language is set to Japanese
- Language for non-unicode programs is set to Japanese
- Java program is run on console
Upon execution, an IOException is encountered, and the message expected in the console is as follows: 既存の接続はリモート ホストに強制的に切断されました。 (translates to "An existing connection was forcibly closed by the remote host") Please see code snippet below:
private void onIOException(IOException e, AbstractConnection connection)
{
String reason = e.getMessage();
...
log.error("Closing ",connection," because ",reason);
}
When running in Java 8, the message is printed correctly. However, when running in Java 9, the message is printed as 譌「蟄倥?ョ謗・邯壹?ッ繝ェ繝「繝シ繝? 繝帙せ繝医↓蠑キ蛻カ逧?縺ォ蛻?譁ュ縺輔l縺セ縺励◆縲?
After some investigation, it was found that in Java 9, the byte array used to represent the same string contains a different set of values ([-24, -83, -116, -17, -67, ...]). In Java 8, the string used to be represented in bytes as ([-26, -105, -94, -27, -83, ...]). In Java 9, if we construct the string using the byte array used in Java 8, the message is printed correctly. This seems to be caused by compact strings as well, since strings are no longer stored as char arrays.
We have tried the following:
- using system property java.locale.providers
- using system property file.encoding
- using console command chcp with different values
- disabling compact strings via "-XX:-CompactStrings"
We've also tried combinations but to no avail as well.
This is related to a previous question IOException message not printed correctly when using Java 9 on Windows 10 set to Japan locale and language as well (I am unable to add details via comment or answer).
Does anybody have an idea on this issue? Thanks!