Issue with IntelliJ run output console not displaying utf-8 characters:

已回答

I have a simple class file that outputs some special characters encoded in UTF-8:
public static void main(String[] args) {
  String str = "1:a\n2:à\n3:ù\n4:§";
  System.err.printf("->[%s]\n",str);
}
When executing it directly inside IDEA the output console prints a question mark instead of the special characters.
->[1:a
2:?
3:?
4:?]
When executing it in a terminal window (in IDEA or outside) it prints the special characters correctly !
Is there a way to fix this garbaged output ? 

Note that I'm running in OSX and using gradle as my build system, but I suppose this shouldn't be important for this issue. 

0

Hello,

It works fine on my side. What IDE version do you use? Could you please attach screenshot from “Settings | Build, Execution, Deployment | Build Tools | Gradle” and “Settings | Editor | File Encodings”?

0

IntelliJ IDEA 2023.3.3 (Community Edition)
Build #IC-233.14015.106, built on January 25, 2024
Runtime version: 17.0.9+7-b1087.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.3
GC: G1 Young Generation, G1 Old Generation
I don't think that it would be important to this case, but although IDEA runs under JDK 17, the application is executed in a JDK 21.

0

There must something on how IntelliJ is running the application, 
From the output it seems the gradle build system is used to do the execution, but I can figure out how it is doing it as when I try to execute gradle on the commandline with the arguments printed on the console and this doesn't work.
But running the compiled class directly with the jdk 21 works correctly in the terminal.
I also checked to make sure on a windows laptop using a different version of Intellij 
IDEA 2023.3.1 and I've got the same issue there.
Passing an vmoption -Dfile.encoding=UTF8 doesn't affect the result.

0

 > Passing an vmoption -Dfile.encoding=UTF8 doesn't affect the result.

Where did you pass it? Could you please attach screenshot from “Settings | Editor | File Encodings”?

0

Please try adding -Dfile.encoding=UTF-8 into IDE main menu Help | Edit Custom VM Options and restart IDE.
Does it help?

0

Added the option to the ide.vmoptions file and restarted intelliJ but it still not showing the special characters. 

1

Could you please attach screenshot from “Settings | Editor | File Encodings”? What is your default OS locale? 

0

I don't know where the default locale is configured in macos.
But when in the terminal I check the LC_CTYPE environment it has the value UTF-8.

0

I finally could solve my issue by adding extra parameters to the idea.vmoptions and restart intelliJ:

I added -Duser.language=en , -Duser.country=US & -Duser.variant=US and now the run output in IntelliJ looks OK.

0

Thanks for the information! Seems error stream uses different locale for some reason. We'll check what might cause the issue.

0

Same problem.

I realized the -Duser.country=US line alone fixes it.

Maybe the IntelliJ team can explain why this is the case and fix it. Are you only applying UTF8 to the standard US region or something?

0
What version of IDE are you using? Previously there was a regression with the related issue and it has been fixed, before which the workaround needs to be applied.

Please check https://youtrack.jetbrains.com/issue/IJPL-156038
0
IntelliJ IDEA 2024.2.4 (Ultimate Edition)
Build #IU-242.23726.103, built on October 23, 2024
Runtime version: 21.0.4+13-b509.26 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS Sequoia 15.1 (24B83)

 

Problem: Compiled Java program output in the bottom “Run” panel (pressing the green play button to run an automatically generated run config on my main App.java class) does NOT display output in UTF8 (several non-English charaters are displayed as ?).

Compiling and running an equivalent gradle build command on iTerm or standard macOS Terminal produces output correctly in UTF8.

Fix: Adding option -Duser.country=US to idea.vmpoptions file using the Help menu fixes it. After restart, ouput in the “Run” panel is correctly displayed in UTF8.

Note: I started using IntelliJ after updating to macOS Sequioa, I cannot comment on whether Sonoma→Sequioa made any difference.

I'm not use how the issue you linked relates to this. Again, I was able to fix this issue with the -Duser.country=US option, adding that alone was enough. Not sure whether that's a workaround or a genuine fix.

0

请先登录再写评论。