Converting Chart to Image raised NullPointerException on Java 11.0.2

Hi. We are in migrating process to jdk-11.0.2 and found, that on Linux server converting chart to image is failed now. If we switched to jdk1.8.0_191, following example will work.

@Test
public void java11_chart_to_image() throws Exception {
    Workbook workbook = new Workbook("E://chart.xlsx");
    ImageOrPrintOptions options = new ImageOrPrintOptions();
    options.setImageType(ImageType.PNG);
    workbook.getWorksheets().get(0).getCharts().get(0).toImage("E://chart.png", options);
}

E.zip (14.6 KB)

I have found, that some like this bug is reported for JDK11

https://bugs.openjdk.java.net/browse/JDK-8204688

Can you please provide - do you have some workarounds for this?

Best regards. Alexey

Exceptions looks like:
Caused by: java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.(Font.java:619)
at java.desktop/java.awt.Font.createFont(Font.java:1225)
at com.aspose.cells.a.d.zaw.a(Unknown Source)
at com.aspose.cells.a.d.zaw.c(Unknown Source)
at com.aspose.cells.a.d.zaw.a(Unknown Source)
at com.aspose.cells.a.d.zbh.a(Unknown Source)
at com.aspose.cells.b.a.b.zg.(Unknown Source)
at com.aspose.cells.b.a.b.zg.(Unknown Source)
at com.aspose.cells.zcad.a(Unknown Source)
at com.aspose.cells.zlc.a(Unknown Source)
at com.aspose.cells.zlc.a(Unknown Source)
at com.aspose.cells.zlc.a(Unknown Source)
at com.aspose.cells.Chart.a(Unknown Source)
at com.aspose.cells.Chart.toImage(Unknown Source)

@makarovalv,

We have tried to check this issue in our similar test environment but no exception is raised. Apparently following can be the reasons:

  1. Required fonts are not installed in your Linux environment or there is some accessibility issue
  2. Some old product version is used as I tested it with latest v19.3.4
  3. There is some issue with JDK 11 in your environment

You may please try to check the first two points i.e. required fonts are installed and latest version 19.3.4 is used. Once you verify these two points, we will investigate this issue accordingly.

You may download the latest version 19.3.4 from the following link:
There are following ways to persist container data:

Hi

There is executable version of test-case (it does not works too). Also, please note, that it failed only for Linux (probably only for Linux x64)

@makarovalv,

Could you please try the following java code in your Linux x64 environment:

import java.awt.Font;
import java.io.File;
Font font = Font.createFont(Font.TRUETYPE_FONT, new File(fontFilePath));

and try to load every font file in your shared font directory.

Let us know your feedback.

Hi.

This code is failed. Is it means, that some error in jdk / environment?

java.lang.InternalError: java.lang.reflect.InvocationTargetException
    at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86) ~[na:na]
    at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
    at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[na:na]
    at java.desktop/java.awt.Font.<init>(Font.java:619) ~[na:na]
    at java.desktop/java.awt.Font.createFont(Font.java:1225) ~[na:na]
    at com.asuproject.aspose.service.FontLoader.load(FontLoader.java:22) ~[classes!/:na]
    at com.asuproject.aspose.AsposeApplication.run(AsposeApplication.java:26) ~[classes!/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]
    at com.asuproject.aspose.AsposeApplication.main(AsposeApplication.java:21) ~[classes!/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[aspose.test-0.0.3.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[aspose.test-0.0.3.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[aspose.test-0.0.3.jar:na]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[aspose.test-0.0.3.jar:na]

Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84) ~[na:na]
… 20 common frames omitted
Caused by: java.lang.NullPointerException: null
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[na:na]
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719) ~[na:na]
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:367) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.SunFontManager.(SunFontManager.java:312) ~[na:na]
at java.desktop/sun.awt.FcFontManager.(FcFontManager.java:35) ~[na:na]
at java.desktop/sun.awt.X11FontManager.(X11FontManager.java:56) ~[na:na]
… 25 common frames omitted

Best regards. Alexey

@makarovalv,

Yes, the stack trace means there is some issue with your environment. Please try to resolve the issue then let us know your feedback.

Hi.

I found, that if we install fontconfig library to our OS, then issue will be fixed. Can you please surround block of loading font by try catch expression and throw some specific exception for futher handling?

Best regards. Alexey

@makarovalv,
Aspose.Cells has provided comprehensive exception handling wherever possible. We have understood your requirement but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as
CELLSJAVA-43126 – Add new exception while failing to load fonts in Linux

@makarovalv,
There are many exceptions about Font and Graphics because of java environment configuration. We can’t catch all of them and rethrow. Catching exception frequently will cause performance issue.

So trying catch the block of loading font is not proper.