javaunicodejvmwindows-11regional-settings

Java doesn't recognize Unicode character in path on Windows 11


Java isn't able to recognize Unicode characters with the Beta: Use Unicode UTF-8 for worldwide language support option enabled.
The path to my user folder is C:\Users\Otávio Augusto Silva, and the á character is causing some trouble for java. By calling the javac command if the JDK is installed inside my user folder using scoop install, it gives the following result:

Erro: Não é possível carregar a classe principal com.sun.tools.javac.Main no módulo jdk.compiler
        java.lang.UnsatisfiedLinkError: no jimage in system library path: C:\Users\Otávio Augusto Silva\scoop\apps\zulu-jdk\current\bin

Notice that it replaces the á character with á.
If installed globally by using scoop install -g, choco install or the default installer from any JDK distribution, the commands works fine, but if I call and pass the whole path, it gives an error:

C:\Users\Otávio Augusto Silva>javac "C:\Users\Otávio Augusto Silva\Documents\Code\Java\Hello World\main.java"
error: file not found: C:\Users\Otávio Augusto Silva\Documents\Code\Java\Hello World\main.java
Usage: javac <options> <source files>
use --help for a list of possible options

To reproduce, do the following:

The error should appear.
I've been stuck for days in this, if anyone can help me it will be greatly appreciated.
Some relevant info:


Solution

  • Using your directory name (Otávio Augusto Silva), I can reproduce your problem on Windows 10 as well, using Java 18. Unfortunately, this looks like a specific example of a more general and longstanding problem documented in this open and unresolved JDK bug:

    JDK-4488646 Java executable and System properties need to support Unicode on Windows

    This is part of the bug report's description, with my emphasis added:

    To make Java completely Unicode-aware on NT we need to

    1. Modify System properties initialization code and all other places where Windows calls are used to use wide-char calls on NT.

    2. Modify java, javac etc. to be able to use Unicode in classpath and other command line arguments.

    That bug report was created in 2001! It relates to Windows NT, but since it remains open and unresolved I assume it has general applicability for all flavors of Windows, including Windows 10 and 11.

    Notes:

    ========================================================

    (This update is based on comments from @user16320675.)

    It seems the issue is fully resolved in Java 19 (download from here) which is due to be released later this month. From the screen shot below:

    I can't find any mention of this fix in the JDK 19 Release Notes.

    ========================================================

    (This update shows what happens if the beta option is not enabled.)

    If the option Beta: Use Unicode UTF-8 for worldwide language support is not enabled I cannot reproduce the problem; the call to javac works fine using both JDK 18 and JDK 19:

    Beta option not enabled

    Note that this works even though the code page in the cmd window is 437, not 65001. Of course there are a couple of significant differences between your environment and mine:

    To summarize how to resolve this issue:

    ========================================================

    Update: The following bug was fixed in Java 19:

    8272352: Java launcher can not parse Chinese character when system locale is set to UTF-8 #530

    Although that bug fix specifically relates to file names passed to java, I think it probably explains why the OP's problem with javac is also resolved in Java 19.