Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-17 Thread Alan Bateman
On Tue, 17 Jan 2023 20:51:36 GMT, Phil Race  wrote:

> Maybe core libs could add such a test.

It is tested by conformance tests but a test could be added to the OpenJDK 
jtreg tests if needed.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-17 Thread Phil Race
On Fri, 6 Jan 2023 22:54:30 GMT, Sergey Bylokhov  wrote:

> But I assume we should have a test somewhere that validates that this option 
> is not null = "is not optional"?

Maybe core libs could add such a test.

The link  doesn't work for me  but I expect I'd need to look at each of those 
cases to understand what they are doing.

It doesn't change that the reason for this proposed change isn't valid.
We probably should remove that debugging property to make it clear.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-06 Thread Sergey Bylokhov
On Fri, 6 Jan 2023 20:42:38 GMT, Phil Race  wrote:

> It is much better to have an error thrown which explains the problem rather 
> than a random NPE or similar right afterwards. 

But I assume we should have a test somewhere that validates that this option is 
not null = "is not optional"?
I make a quick search of code where we read the conf files, and it seems:
https://github.com/search?q=%22java.home%22+repo%3Aopenjdk%2Fjdk+path%3Asrc%2Fjava.desktop%2F+language%3AJava+language%3AJava&type=Code&ref=advsearch&l=Java&l=Java

 * The Sound - throw an exception in one place, but ignores the null in another 
place
 * The Fontconfig - throw an exception in FcFontConfiguration.java, but 
fallback to the empty code in SunFontManager.java
 * The Swing ignores the null property
 * The metal pipeline fallback to the empty path
 * The a11y code just read it as is.
 * The printers code in PSPrinterJob ignores the null

We have an opportunity to clean up all that code.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-06 Thread Phil Race
On Fri, 6 Jan 2023 00:49:58 GMT, Sergey Bylokhov  wrote:

> If this property is not optional why do we have a null check for it? Can that 
> check be removed as a part of refactoring?

It is much better to have an error thrown which explains the problem rather 
than a random NPE or similar right afterwards.
This behaviour has been there since at least JDK 1.3 (2000)  when the file was 
first created as sun/awt/FontProperties.java. It may even have existed in some 
other location before then, but I can't tell that from SCCS per-file history.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-05 Thread Sergey Bylokhov
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

If this property is not optional why do we have a null check for it? Can that 
check be removed as a part of refactoring?

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2023-01-03 Thread Phil Race
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

FYI here's an almost 9 year old bug report where I make clear the unsupported 
nature of that property. https://bugs.openjdk.org/browse/JDK-8038987

Seems this PR should be withdrawn and the bug report closed as external or not 
an issue.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-30 Thread Alexander Scherbatiy
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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/b6e1c8d0844c475c97ad7ef52796b192b59ef2fc/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 

Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-28 Thread Alan Bateman
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-23 Thread Phil Race
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

> There is the `Java system properties are inconsistent between traditional JDK 
> and native image` issue in Graal: 
> [oracle/graal#2835](https://github.com/oracle/graal/issues/2835)
> 
> With comment: [oracle/graal#2835 
> (comment)](https://github.com/oracle/graal/issues/2835#issuecomment-100103)
> 
> > We are still not setting the `java.home` system property at image run time 
> > by default, and do not plan to change that. Because there is just no "JDK 
> > home directory" around at image run time, so setting `java.home` to, for 
> > example, the directory where the native image is located in is misleading - 
>

Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-23 Thread Alexander Scherbatiy
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

There is the `Java system properties are inconsistent between traditional JDK 
and native image` issue in Graal: https://github.com/oracle/graal/issues/2835

With comment: 
https://github.com/oracle/graal/issues/2835#issuecomment-100103
> We are still not setting the `java.home` system property at image run time by 
> default, and do not plan to change that. Because there is just no "JDK home 
> directory" around at image run time, so setting `java.home` to, for example, 
> the directory where the native image is located in is misleading - files that 
> might be expected to be in that directory are not there.

--

Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-23 Thread Phil Race
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

Why is it not set ? That seems wrong.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-22 Thread Sergey Bylokhov
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

Marked as reviewed by serb (Reviewer).

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-22 Thread Alexander Scherbatiy
On Thu, 22 Dec 2022 10:57:15 GMT, Alexander Scherbatiy  
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.(FontConfiguration.java:97)
>> at 
>> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

Could you review the updated fix? The `javaLib` variable is initialized even 
`userConfigFile` is not null.

-

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


Re: RFR: 8298266: "java.home property not set" error in Graal when sun.awt.fontconfig java property is set on Windows [v2]

2022-12-22 Thread Alexander Scherbatiy
> **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.(FontConfiguration.java:97)
> at 
> java.desktop@19.0.1/sun.awt.windows.WFontConfiguration.(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

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/11559/files
  - new: https://git.openjdk.org/jdk/pull/11559/files/f50dc866..f882a0eb

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=11559&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=11559&range=00-01

  Stats: 6 lines in 1 file changed: 4 ins; 2 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/11559.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11559/head:pull/11559

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