[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property 
From:       Alexander Scherbatiy <alexsch () openjdk ! org>
Date:       2022-12-30 9:55:06
Message-ID: F4SV412DqkLOauA5TcpfgkjLCjQWNce8GJpCYNtSr4Y=.40302da7-f9e1-4f2f-a239-37d85ea03189 () github ! com
[Download RAW message or body]

On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy <alexsch@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/c9 \
> > d485792b99233f381dcdfd69838e7b973909bd/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)
> > 
> 
> 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

Graal uses a substitutor which replaces \
[FontConfiguration.findFontConfigFile()](https://github.com/oracle/graal/blob/b6e1c8d0 \
844c475c97ad7ef52796b192b59ef2fc/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaAWTSubstitutions.java#L99
 ) method to empty on Linux.
This does not work on Windows because it requires to read logical fonts from \
fontconfig.properties file.

The idea of the fix was to allow to use `sun.awt.fontconfig` property in Graal.
If  `sun.awt.fontconfig` property is not a supported documented property then may be \
it is better to put the fontconfig.properties file as a resource during a native \
image generation and read it when the application is executed.

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

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic