azure-functions-java-worker icon indicating copy to clipboard operation
azure-functions-java-worker copied to clipboard

Fatal error "No fonts found" when calling `GraphicsEnvironment.getAvailableFontFamilyNames()` (Java AWT)

Open pacon-vib opened this issue 5 years ago • 2 comments

I'm running a Java Function App that calls the JasperReports library. When I "fill" a report (i.e. put together the template and data to produce a PDF report) the function throws an exception and dies. This is code that normally runs on an Ubuntu virtual machine.

For the purposes of this bug report I isolated the specific call to Java AWT that fails.

Investigative information

  • Timestamp: 2020-09-02T05:48:54.3526633Z
  • Invocation ID: 91ea1106-4ffd-40d3-970c-2fc321f68c1f
  • Region: Australia East

Repro steps

import java.awt.GraphicsEnvironment;
import java.util.Arrays;

context.getLogger().info("Trying to get graphics context...");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

context.getLogger().info("Trying to get list of font families...");
String[] fontFamilies = ge.getAvailableFontFamilyNames(); // this is the line that throws the exception

Arrays.stream(fontFamilies).forEach(name -> {
    context.getLogger().info("Found font family \"" + name + "\".");
});
context.getLogger().info("Done listing font families");

Expected behavior

When I run the same code in Functions Core Tools on my Macbook with the same input, the function runs successfully and prints a list of font families. Invocation ID d6071fb6-d3d0-448f-a24c-cabfeb660b0d (2/9/2020 8:00:39 am UTC)

Actual behavior

Got exception:

Result: Failure
Exception: Error: Probable fatal error:No fonts found.
Stack: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.lang.Error: Probable fatal error:No fonts found.
at sun.font.SunFontManager.getDefaultPhysicalFont(SunFontManager.java:1236)
...
at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:94)
at net.example.reportservice.Function.runPrintJob(Function.java:86)

Line 86 of Function.java is the line that says String[] fontFamilies = ge.getAvailableFontFamilyNames();

Known workarounds

  • Nil

Related information

  • Java 8
  • Function is triggered by an Azure Service Bus queue
  • Based on similar error messages reported elsewhere, I think the underlying problem is that there are no fonts and no font configuration file e.g. https://github.com/corretto/corretto-11/issues/124#issuecomment-678118395
  • For any other JasperReports users stumbling across this ticket, the original code was calling JasperFillManager.fillReportToFile().

Please let me know if I can provide any further information. Thankyou for your consideration.

pacon-vib avatar Sep 02 '20 23:09 pacon-vib

Hello @pacon-vib , Thank you for the report! Under the hood, we run the code as docker container for Linux. If you are using Linux based Azure Functions, how about using Custom Container? Then you can install your font that you need. e.g. https://stackoverflow.com/questions/14066525/java-lang-error-probable-fatal-errorno-fonts-found

TsuyoshiUshio avatar Sep 12 '20 01:09 TsuyoshiUshio

@pacon-vib hey do you have any update for @TsuyoshiUshio suggestion?

amamounelsayed avatar Oct 19 '20 20:10 amamounelsayed