Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garbled characters occur when executing run tasks from extensions with Java21. #1480

Open
mazeneko opened this issue Apr 4, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mazeneko
Copy link

mazeneko commented Apr 4, 2024

Extension Name: vscode-gradle
Extension Version: 3.13.5
OS Version: Windows11 23H2
VSCode version: 1.87.2
Java version: 21

Describe the bug
Garbled characters occur when executing run tasks from extensions with Java21.

Gradle outputs in MS932 and the terminal tries to display in UTF-8.

To Reproduce
reproduction tag commit of reproduction code repository

Expected behavior
Gradle outputs in UTF-8 and the terminal tries to display in UTF-8.

Screenshots
. /gradlew run in a terminal, no problem.
image

Garbled characters occur when executing run tasks from extensions.
image

@mazeneko mazeneko added the bug Something isn't working label Apr 4, 2024
@cypher256
Copy link

cypher256 commented Apr 5, 2024

The task can be executed correctly by setting the following in build.gradle.

application {
    mainClass = '...'
    applicationDefaultJvmArgs = ['-Dstdout.encoding=UTF-8', '-Dstderr.encoding=UTF-8']
}

However, if you run it in the terminal, you need to specify chcp 65001.
You can create a terminal profile by setting the following in settings.json.

"terminal.integrated.profiles.windows": {
    "JavaSE-21": {
        "overrideName": true,
        "env": {
            "PATH": "D:\\xxx\\java\\21\\bin;${env:PATH}",
            "JAVA_HOME": "D:\\xxx\\java\\21"
        },
        "path": "cmd",
        "args": [
            "/k",
            "chcp",
            "65001"
        ]
    }
},
"terminal.integrated.defaultProfile.windows": "JavaSE-21",
"terminal.integrated.automationProfile.windows": {
    "path": "cmd"
},
"java.test.config": {
    "vmArgs": [
        "-Dstdout.encoding=UTF-8",
        "-Dstderr.encoding=UTF-8"
    ]
},

These settings can be automatically configured with the Extension Pack for Java Auto Config extension that I provide.

@mazeneko
Copy link
Author

mazeneko commented Apr 5, 2024

Thanks for the advice.

I'm aware that if I set Java and the terminals to UTF-8, the characters will not be garbled, and in fact I have avoiding the problem by doing so in my apps.
However, this requires writing the settings for each of the various terminals used by the development team members.
(And... every time you create a new project!)

I am focusing on the fact that the "Java outputs characters in UTF-8 and terminal tabs in UTF-8" behavior that worked in Java 17 is no longer working in Java 21.
(Perhaps the influence of JEP400?)

This is my uncertain guess,
I think need to set the Java output to UTF-8 in the extension, since the encoding of the terminal tab cannot be changed from UTF-8 when run from the extension.

@cypher256
Copy link

cypher256 commented Apr 5, 2024

Although it may not be a solution, Java encoding can be specified in settings.json. However, in this case, characters will be garbled when executing the command in the terminal. What has changed in JEP 400 is file.encoding.

"java.import.gradle.jvmArguments": "-Dfile.encoding=COMPAT"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants