I’m getting a null pointer exception when saving a PDF to DOCX using the com.aspose.pdf.Document.save() method. This worked fine in Java 8 but fails in Java 11. Specifically, the AWS Lambda Java 11 (Corretto) runtime. I suspect it’s related to Java 11 not including additional fonts, but I don’t see how to address this using com.aspose.pdf package. The stack traceis below.
Thanks,
Bob
java.lang.reflect.InvocationTargetException: java.lang.InternalError
java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getAllFonts(Unknown Source)
at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getAllFonts(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.lk(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v$2.lI(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v$2.lf(Unknown Source)
at com.aspose.pdf.internal.l13p.lI.lb(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.lj(Unknown Source)
at com.aspose.pdf.internal.l4k.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l4y.l1h.lc(Unknown Source)
at com.aspose.pdf.internal.l4y.l1h.l1h(Unknown Source)
at com.aspose.pdf.internal.l3p.lI.lI(Unknown Source)
at com.aspose.pdf.internal.l3p.lj.lI(Unknown Source)
at com.aspose.pdf.internal.l2u.lu.lj(Unknown Source)
at com.aspose.pdf.internal.l2u.lu.lb(Unknown Source)
at com.aspose.pdf.internal.l2u.lu.lf(Unknown Source)
at com.aspose.pdf.internal.l2u.lu.lf(Unknown Source)
at com.aspose.pdf.l12f.lI(Unknown Source)
at com.aspose.pdf.l12f.lb(Unknown Source)
at com.aspose.pdf.ApsUsingConverter.lI(Unknown Source)
at com.aspose.pdf.ApsUsingConverter.lf(Unknown Source)
at com.aspose.pdf.l4j.lI(Unknown Source)
at com.aspose.pdf.ADocument.lj(Unknown Source)
at com.aspose.pdf.ADocument.lI(Unknown Source)
at com.aspose.pdf.Document.lI(Unknown Source)
at com.aspose.pdf.ADocument.lI(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.elsevier.scival.lambda.Handler.convertPdfToDocx(Handler.java:250)
at com.elsevier.scival.lambda.Handler.handleRequest(Handler.java:143)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
… 39 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.init(Unknown Source)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(Unknown Source)
at java.desktop/sun.font.SunFontManager$2.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.(Unknown Source)
at java.desktop/sun.awt.FcFontManager.(Unknown Source)
at java.desktop/sun.awt.X11FontManager.(Unknown Source)
… 43 more
We have logged an investigation ticket in our issue tracking system to further analyze this issue. Meanwhile, can you please try using FontRepository.setLocalFontPaths() method to include the additional font directories for the API to scan during conversion? We will further look into this matter and let you know as soon as the ticket is resolved.
Using setLocalFontPaths has a similar result (null pointer, see below). Again, feels like the underlying problem is fonts no longer in Java 11 and not properly set in the runtime environment, AWS Lambda Java 11 (Corretto). Btw, I’m using aspose-pdf-21.7.jar
java.lang.reflect.InvocationTargetException: java.lang.InternalError
java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getAllFonts(Unknown Source)
at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getAllFonts(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.lk(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v$2.lI(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v$2.lf(Unknown Source)
at com.aspose.pdf.internal.l13p.lI.lb(Unknown Source)
at com.aspose.pdf.internal.l4y.l0v.lj(Unknown Source)
at com.aspose.pdf.FontRepository.addLocalFontPath(Unknown Source)
at com.aspose.pdf.FontRepository.setLocalFontPaths(Unknown Source)
at com.elsevier.scival.lambda.Handler.installFonts(Handler.java:338)
at com.elsevier.scival.lambda.Handler.handleRequest(Handler.java:103)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
… 21 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.init(Unknown Source)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(Unknown Source)
at java.desktop/sun.font.SunFontManager$2.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.(Unknown Source)
at java.desktop/sun.awt.FcFontManager.(Unknown Source)
at java.desktop/sun.awt.X11FontManager.(Unknown Source)
… 25 more
We have updated the information of the logged ticket i.e. PDFJAVA-40786. We will look into its details and let you know as soon as it is resolved. Please be patient and spare us some time.
We will surely investigate the ticket from this perspective and let you know as soon as we have some updates regarding its resolution. Please give us some time.