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

UnsupportedCharsetException: cp65001 with vs code #1474

Closed
epuni opened this issue Nov 20, 2021 · 9 comments
Closed

UnsupportedCharsetException: cp65001 with vs code #1474

epuni opened this issue Nov 20, 2021 · 9 comments
Labels
theme: compatibility Issues related to binary and source backwards compatibility theme: shell An issue or change related to interactive (JLine) applications type: bug 🐛
Milestone

Comments

@epuni
Copy link

epuni commented Nov 20, 2021

I was trying out this library in an empty java + maven project in vs code on windows 10, upon running any simple application i get this:

Exception in thread "main" java.nio.charset.UnsupportedCharsetException: cp65001
        at java.base/java.nio.charset.Charset.forName(Charset.java:526)
        at picocli.CommandLine.getStderrEncoding(CommandLine.java:14531)
        at picocli.CommandLine.getErr(CommandLine.java:1236)
        at picocli.CommandLine.handleUnhandled(CommandLine.java:2097)
        at picocli.CommandLine.execute(CommandLine.java:2083)
        at com.example.App.main(App.java:24)

The command line of the vs code java extension when launching as debug is the following:

cmd /C "C:\Users\<username>\.vscode\extensions\vscjava.vscode-java-debug-0.36.0\scripts\launcher.bat "C:\Program Files\OpenJDK\bin\java.exe" -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:54512 -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 @C:\Users\<username>\AppData\Local\Temp\<random name>.argfile com.example.App <actual application arugments>"

The cause seems to be the default launcher.bat which does:

REM Change code page to UTF-8 for better compatibility.
@chcp.com 65001 > NUL 

The only other reference to this problem is in #1457 but it's related to argument files while it's not the case here (at least i think, the argfile here seems to be used only for vm args).
The fix proposed in that PR doesn't work as the command line already includes -Dfile.encoding=UTF-8.

I tried adding several options such as -Dsun.stdout.encoding=UTF8 -Dsun.err.encoding=UTF8 to the vmargs and none worked, ultimately the the only workaround to get it working for me was changing code page to 850 (cmd's default one) in launcher.bat which is not desirable as it will be overwritten when the extension updates and i don't know if it may break other projects.

Is there anything i'm missing ? Guess even if it's not a problem on your end it's worth noting it in the docs.

@epuni
Copy link
Author

epuni commented Nov 20, 2021

Minimal way to reproduce this without vs code:
Build anything with picocli, then in a cmd run the follwing

chcp 65001
java -jar demo.jar
REM Won't work either:
java -DFile.encoding=UTF8 -jar demo.jar

@remkop
Copy link
Owner

remkop commented Nov 21, 2021

@epuni Thank you for raising this!
Are you also seeing this error with the previous version: picocli 4.6.1?

It is likely that this is caused by a recent change in the 4.6.2 release (https://github.com/remkop/picocli/releases/tag/v4.6.2).

@epuni
Copy link
Author

epuni commented Nov 21, 2021

Just tested 4.6.1 and it works as expected.

@remkop remkop added type: bug 🐛 theme: shell An issue or change related to interactive (JLine) applications labels Nov 21, 2021
@remkop remkop added this to the 4.6.3 milestone Nov 21, 2021
@remkop
Copy link
Owner

remkop commented Nov 21, 2021

Thank you for the confirmation.
This looks like a regression introduced by #1320 #1321.
I will add some code to set UTF-8 instead when the String cp65001 is specified.

@remkop
Copy link
Owner

remkop commented Nov 21, 2021

Does anyone have any idea how to add a unit test for this? :-)

@remkop remkop closed this as completed in f98a4ae Nov 21, 2021
@remkop
Copy link
Owner

remkop commented Nov 21, 2021

I pushed a fix that should address this issue. Thank you again for raising this!

(Ideas for unit testing this still welcome. 😅 )

@remkop remkop added the theme: compatibility Issues related to binary and source backwards compatibility label Nov 21, 2021
@Druckles
Copy link

I've just had the same problem in Cygwin with cp20127:

Exception in thread "main" java.nio.charset.UnsupportedCharsetException: cp20127

        at java.base/java.nio.charset.Charset.forName(Charset.java:528)
        at picocli.CommandLine.getStderrEncoding(CommandLine.java:14531)
        at picocli.CommandLine.getErr(CommandLine.java:1236)
        at picocli.CommandLine.handleUnhandled(CommandLine.java:2097)
        at picocli.CommandLine.execute(CommandLine.java:2093)
  ...

Downgrading to 4.6.1 fixed the problem.

@remkop
Copy link
Owner

remkop commented Aug 11, 2022

@Druckles Thank you for raising this!
would you mind raising a separate ticket for this?

@remkop
Copy link
Owner

remkop commented May 25, 2023

I've just had the same problem in Cygwin with cp20127:

Exception in thread "main" java.nio.charset.UnsupportedCharsetException: cp20127

        at java.base/java.nio.charset.Charset.forName(Charset.java:528)
        at picocli.CommandLine.getStderrEncoding(CommandLine.java:14531)
        at picocli.CommandLine.getErr(CommandLine.java:1236)
        at picocli.CommandLine.handleUnhandled(CommandLine.java:2097)
        at picocli.CommandLine.execute(CommandLine.java:2093)
  ...

Downgrading to 4.6.1 fixed the problem.

It is unclear whether this is a Cygwin issue, or what else is going on... (potentially related: rubygems/rubygems#4871, which mentions "Platforms ruby, x64-mingw32": also cygwin)

Unclear how to remediate this in picocli (if we wanted to): what Java encoding should be used when system property sun.stderr.encoding has value cp20127?

(And for bookkeeping purposes, if further action is required, we need to create a new ticket.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: compatibility Issues related to binary and source backwards compatibility theme: shell An issue or change related to interactive (JLine) applications type: bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants