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

[Native Image] AWT component MenuItem shows wrong characters. #9816

Open
2 tasks
hyranno opened this issue Oct 4, 2024 · 0 comments
Open
2 tasks

[Native Image] AWT component MenuItem shows wrong characters. #9816

hyranno opened this issue Oct 4, 2024 · 0 comments

Comments

@hyranno
Copy link

hyranno commented Oct 4, 2024

Describe the Issue

Running built native image on Windows, AWT component MenuItem shows wrong characters.
MenuItem on SystemTray PopupMenu shows characters with inverted byte order.
Other OSs or AWT components are unverified.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)

Operating System and Version

Windows 22H2 (19045.4894)

Diagnostic Flag Confirmation

  • I tried the -H:ThrowMissingRegistrationErrors= flag.

Run Command

javac -d ./java ./Reproduce.java
java -agentlib:native-image-agent=config-output-dir=./java/META-INF/native-image -cp ./java ./Reproduce.java
cp ./native-image.properties ./java/META-INF/native-image
cd ./java
jar -c -f ./Reproduce.jar -e Reproduce -C ./ .
cd ..
mkdir native
native-image -jar ./java/Reproduce.jar ./native/Reproduce
cp -r ./java_home ./native
./native/Reproduce.exe

Expected Behavior

AWT MenuItem on SystemTray PopupMenu shows "Reproduce"

Actual Behavior

AWT MenuItem on SystemTray PopupMenu shows "刀攀瀀爀漀搀甀挀攀".
Each character has inverted byte order of UTF-16 "Reproduce".

Steps to Reproduce

Put files in current directory :

Reproduce.java
native-image.properties
java_home/conf/fonts/fontconfig.properties

Reproduce.java

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Path;

public class Reproduce extends Frame {
  public static void main(String [] args) {
    new Reproduce();
  }
  Reproduce() {
    super("Reproduce");
    setJavaHome();
    setSize(400, 100);
    addWindowListener(new SimpleWindowAdapter());
    setVisible(true);
    addTray();
  }

  private void addTray() {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu popup = new PopupMenu();
    Image image = new BufferedImage(36, 36, BufferedImage.TYPE_INT_RGB);
    TrayIcon icon = new TrayIcon(image, "Reproduce", popup);
    icon.setImageAutoSize(true);

    MenuItem item1 = new MenuItem("Reproduce");
    item1.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
      System.out.println("Reproduce");
      }
    });
    popup.add(item1);

    try {
      tray.add(icon);
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }

  private void setJavaHome() {
    String original = System.getProperty("java.home");
    boolean exists = !(original == null || !new File(original).exists());
    if (!exists) {
      Path exePath = (new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath())).toPath();
      Path home = exePath.getParent().resolve("java_home");
      System.setProperty("java.home", home.toString());
      System.out.println("java.home override : " + home);
    }
  }

}

class SimpleWindowAdapter extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
       System.exit(0);
    }
}

native-image.properties

Args = \
    --no-fallback \
    -H:+UnlockExperimentalVMOptions \
    -H:+AddAllCharsets \
    -H:ReflectionConfigurationResources=${.}/reflect-config.json \
    -H:ResourceConfigurationResources=${.}/resource-config.json \
    -H:SerializationConfigurationResources=${.}/serialization-config.json \
    -H:JNIConfigurationResources=${.}/jni-config.json \
    -H:DynamicProxyConfigurationResources=${.}/proxy-config.json

fontconfig.properties is the copy of %JAVA_HOME%/lib/fontconfig.properties.src

Then run the commands described above.

Additional Context

Without java_home/conf/fonts/fontconfig.properties, MenuItem does not show any characters.
Setting system property java.home for it runtime.

Run-Time Log Output and Error Messages

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant