'Apache POI FontConfiguration NPE on Azure
I have a Azure Linux Webapp using Apache poi that is raising the following error:
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)
...
Caused by: java.lang.NullPointerException: null
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:379)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:324)
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
... 198 common frames omitted
I have seen that such error can happen using openjdk, and can be solved doing some conf, but how to solve this on Azure?
Doing some tests, I have found that it is working fine using java 11.0.11 instead of last default one 11.0.12, the thing is that I didn't found any way to force the minor version of java using "az webapp create" command. So I am stuck here...
Solution 1:[1]
You can try creating webapp using --runtime in azure-cli:
For example:
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName --runtime "java|11|Java SE|11"
If that doesn’t work, for a workaround, you can try selecting the required version from configuration blade on portal:
References: java 8 - Azure web app (Linux) started throwing font error for apache poi xlsx export - Stack Overflow , Java NPE error and java minor version selection · Issue #21540 · Azure/azure-cli · GitHub and azure - Problem in Powershell with the --runtime command setting up Jenkins pipeline - Stack Overflow
Solution 2:[2]
What I finally found, is that it is possible to specify java minor version on a Yaml Azure Devops pipeline, doing something like:
- task: AzureWebApp@1
displayName: 'Azure Web App Deploy'
inputs:
azureSubscription: MY_SUBS
appType: webAppLinux
appName: MY_APP_NAME
package: MY_PACKAGE
runtimeStack: 'JAVA|11.0.11'
Available minor versions can be found on file: https://github.com/Azure/azure-functions-ux/blob/dev/server/src/stacks/2020-10-01/stacks/web-app-stacks/JavaContainers.ts
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MadhurajVadde-MT |
| Solution 2 | Florent |
