Skip to content

Bug: Formatter breaks accented characters on Windows due to Java 18+ stdio encoding #1

Description

@nneto

Description:
When formatting a UTF-8 file on Windows using Java 18 or higher (I'm using Java 25), characters with accents/tildes are replaced with the replacement character.

Root Cause:
The extension communicates with the JVM daemon via stdin/stdout. Starting in Java 18 (JEP 400), while file.encoding defaults to UTF-8, the Standard I/O streams (System.out, System.in, System.err) default to the native console encoding (e.g., CP1252 or CP850 on Windows). Because the daemon reads and writes the JSON payload via stdio without forcing UTF-8, the characters get mangled during the VS Code <-> JVM IPC exchange.

Workaround used:
I was able to fix this locally by adding the following to my palantirJavaFormat.jvmArgs:

-Dfile.encoding=UTF-8
-Dstdout.encoding=UTF-8
-Dstderr.encoding=UTF-8
-Dstdin.encoding=UTF-8

Suggested Fix for the Extension:
To fix this for all users out of the box, you could either:

  1. (Extension side): Automatically inject these encoding flags into the JVM arguments when spawning the daemon process in extension.ts.
  2. (Daemon side): Explicitly wrap System.in and System.out using StandardCharsets.UTF_8 inside the Java daemon when handling the I/O streams, rather than relying on the platform's default standard stream encoding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions