On Wed, 7 Dec 2022 13:20:10 GMT, Alexander Scherbatiy <alex...@openjdk.org> 
wrote:

> **Environment**: 
> GraalVM 22.3.0 with  jdk 19, Windows OS.
> 
> **Description**:
> Create a native image of Swing application using GraalVM and run it with ` 
> -Dsun.awt.fontconfig=fontconfig.properties.src` java property.
> `java.lang.Error: java.home property not set` error is thrown.
> 
> For more details see https://github.com/oracle/graal/issues/4875.
> 
> **Solution**:
> The error is thrown by the code from 
> [FontConfiguration.findFontConfigFile()](https://github.com/openjdk/jdk19u/blob/c9d485792b99233f381dcdfd69838e7b973909bd/src/java.desktop/share/classes/sun/awt/FontConfiguration.java#L175)
>  method.
> GraalVM does not set `java.home`  property, that is why the `java.lang.Error: 
> java.home property not set` is thrown.
> `FontConfiguration.findFontConfigFile()` method compares `java.home` property 
> to null before checking user provided `sun.awt.fontconfig` java property.
> 
> The proposed fix swaps the order of `java.home` and `sun.awt.fontconfig` 
> properties checking to avoid using `java.home` property in case 
> `sun.awt.fontconfig` is set.
> 
> 
> **Steps to reproduce**:
> - Download graal 22.3.0 jdk 19 for Windows from [GraalVM Community Edition 
> 22.3.0](https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-22.3.0) 
> page.
> - Install native-image
> 
> graalvm-ce-java19-22.3.0\bin\gu.cmd install native-image
> 
> - Create and compile `SwingSample.java` sample
> 
> import java.awt.*;
> import javax.swing.*;
> 
> public class SwingSample {
>     public static void main(String[] args) throws Exception {
>         SwingUtilities.invokeAndWait(() -> {
> 
>             JFrame frame = new JFrame("Hello World");
> 
>             JButton button = new JButton("Hello");
>             button.addActionListener(e -> {
>                 System.out.printf("Hello, World!%n");
>             });
> 
>             JPanel panel = new JPanel(new FlowLayout());
>             panel.add(button);
> 
>             frame.add(panel);
>             frame.setSize(400, 300);
>             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>             frame.setVisible(true);
>         });
>     }
> }
> 
> - Run native-image-agent to generate configuration files
> 
> graalvm-ce-java19-22.3.0\bin\java.cmd 
> -agentlib:native-image-agent=config-output-dir=conf-dir SwingSample
> 
> - Copy `graalvm-ce-java19-22.3.0\lib\fontconfig.properties.src` file to the 
> sample dir
> - Generate native image with configuration files and 
> `-Djava.awt.headless=false `, 
> `-Dsun.awt.fontconfig=fontconfig.properties.src` java properties
> 
> call "C:\Program Files (x86)\Microsoft Visual 
> Studio\2019\Community\VC\Auxiliary\Build\vcvars64"
> graalvm-ce-java19-22.3.0\bin\native-image.cmd --no-fallback 
> -Djava.awt.headless=false -Dsun.awt.fontconfig=fontconfig.properties.src 
> -H:ResourceConfigurationFiles=conf-dir/resource-config.json 
> -H:SerializationConfigurationFiles=conf-dir/serialization-config.json 
> -H:ReflectionConfigurationFiles=conf-dir/reflect-config.json 
> -H:JNIConfigurationFiles=conf-dir/jni-config.json SwingSample
> 
> - Run the native image with `-Dsun.awt.fontconfig=fontconfig.properties.src` 
> java property.
> 
> swingsample.exe  -Dsun.awt.fontconfig=fontconfig.properties.src
> 
> Exception in thread "main" java.lang.reflect.InvocationTargetException
>         at 
> java.desktop@19.0.1/java.awt.EventQueue.invokeAndWait(EventQueue.java:1371)
>         at 
> java.desktop@19.0.1/java.awt.EventQueue.invokeAndWait(EventQueue.java:1346)
>         at 
> java.desktop@19.0.1/javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1480)
>         at SwingSample.main(SwingSample.java:7)
> Caused by: java.lang.Error: java.home property not set
>         at 
> java.desktop@19.0.1/sun.awt.FontConfiguration.findFontConfigFile(FontConfiguration.java:180)
>         at 
> java.desktop@19.0.1/sun.awt.FontConfiguration.<init>(FontConfiguration.java:97)
>         at 
> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.<init>(WFontConfiguration.java:41)

This pull request has been closed without being integrated.

-------------

PR: https://git.openjdk.org/jdk/pull/11559

Reply via email to