RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]
Alan Bateman
alanb at openjdk.org
Thu Dec 29 06:39:48 UTC 2022
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy <alexsch at 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 at 19.0.1/java.awt.EventQueue.invokeAndWait(EventQueue.java:1371)
>> at java.desktop at 19.0.1/java.awt.EventQueue.invokeAndWait(EventQueue.java:1346)
>> at java.desktop at 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 at 19.0.1/sun.awt.FontConfiguration.findFontConfigFile(FontConfiguration.java:180)
>> at java.desktop at 19.0.1/sun.awt.FontConfiguration.<init>(FontConfiguration.java:97)
>> at java.desktop at 19.0.1/sun.awt.windows.WFontConfiguration.<init>(WFontConfiguration.java:41)
>
> Alexander Scherbatiy has updated the pull request incrementally with one additional commit since the last revision:
>
> Initialize javaLib when a user fontconfig file is set
The table in System.getProperties() lists the standard system properties. java.home is not optional. It's not hard to find code that reads the value of this property and it would be a major compatibility issue to change java.home to be optional.
-------------
PR: https://git.openjdk.org/jdk/pull/11559
More information about the client-libs-dev
mailing list