JDK-8277046 : Incorrect default encoding for System.getLogger(..).log(..) console output
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 11,17
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-11-10
  • Updated: 2024-09-11
  • Resolved: 2024-09-11
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Microsoft Windows [version 10.0.19043.1348]
OpenJDK Runtime Environment (build 18-ea+22-1416)
Windows with French locale

A DESCRIPTION OF THE PROBLEM :
The default encoding for System.getLogger(..).log(..) console output is incorrect

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Copy the given program into src\main\java\mavenproject3\
Compile the given program with javac src\main\java\mavenproject3\*.java
Run with java -cp src\main\java mavenproject3.NewMain

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program is expected to print (instant adjusted - e acute t e acute):
été
nov. 10, 2021 3:56:11 PM mavenproject3.NewMain main
INFO: été
ACTUAL -
The program prints (instant adjusted):
été
nov. 10, 2021 3:56:11 PM mavenproject3.NewMain main
INFO: ├®t├®

---------- BEGIN SOURCE ----------
package mavenproject3;
public class NewMain
{
  public static void main(String[] args)
  {
    String msg = "été";
    System.out.println(msg);
    System.getLogger("Main").log(System.Logger.Level.INFO, msg);
  }  
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Requested the submitter verify that the issue is no longer present in the latest build of JDK 18 at https://jdk.java.net/18/
09-12-2021

The issue should have been fixed by JDK-8276970 in JDK 18 build 25 - which is now available in early access at https://jdk.java.net/18/ I have added 18-na to this issue labels.
29-11-2021

JDK-8276970 should fix the issue in JDK 18. If a variant of JDK-8276970 cannot be backported, and a fix limited to j.u.logging is necessary on earlier releases, then a point fix could be attempted in j.u.l.ConsoleHandler, when setting the output stream to System.err, to also explicitly set the encoding that will be used by the Writer. That would only solve the issue for java.logging though.
18-11-2021

We think this issue will go away once JDK-8276970 is addressed.
13-11-2021

It seems that this is not a regression caused by the JEP 400, but caused by the charset inconsistency on wrapping a PrintStream(incl. System.out/err) in OutputStreamWriter/PrintWriter, or even chaining PrintStreams like `new PrintStream(printStream)`. Here is output on Windows 10 (French-France) with JDK 18ea, JDK18ea (with file.encoding=COMPAT), JDK17, and JDK18ea (with a tentative fix to JDK-8276970, with and without COMPAT), respectively: ``` C:\Users\nsato>d:\projects\jdk\git\utf8\build\windows-x64\jdk\bin\java NewMain été nov. 12, 2021 9:13:57 PM NewMain main INFO: ├®t├® C:\Users\nsato>d:\projects\jdk\git\utf8\build\windows-x64\jdk\bin\java -Dfile.encoding=COMPAT NewMain été nov. 12, 2021 9:14:04 PM NewMain main INFO: ÚtÚ C:\Users\nsato>java -version java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing) C:\Users\nsato>java NewMain été nov. 12, 2021 9:14:29 PM NewMain main INFO: ÚtÚ C:\Users\nsato>d:\projects\jdk\git\jdk\build\windows-x64\jdk\bin\java -Dfile.encoding=COMPAT NewMain été nov. 12, 2021 9:43:05 PM NewMain main INFO: été C:\Users\nsato>d:\projects\jdk\git\jdk\build\windows-x64\jdk\bin\java NewMain été nov. 12, 2021 9:43:19 PM NewMain main INFO: été ``` Note that both JDK18/JDK17 print garbled chars, but differently. That's because the default charset is different. (cp850 -> windows1252 in JDK17, cp850 -> UTF-8 in JDK18).
13-11-2021

Andrew's comment suggests this also duplicates with JDK 11 and JDK 17. It would be useful to get confirmation on this, that helps to know if this is related to JEP 400 or not. Note that there are a few follow-on issues from JEP 400, including wrapping of PrintStreams that use the native encoding, which may be related the issue here.
12-11-2021

The observations on Windows 10: JDK 11: Failed, console output is incorrect JDK 17: Failed. JDK 18ea+1: Failed.
12-11-2021