Bug 65260 - Creating an SXSSFWorkbook fails if no fonts are available on the system
Summary: Creating an SXSSFWorkbook fails if no fonts are available on the system
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 4.1.2-FINAL
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-22 10:04 UTC by Alex
Modified: 2021-04-27 05:53 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2021-04-22 10:04:16 UTC
Good day.
We use Apache POI 4.1.2 for creation .xlsx file.
Our application starts inside Docker container.
We use open-jdk(11th version) without predefined fonts. We needs that for security reason.
At firts time we used XSSFWorkbook/XSSFSheet. All worked correctly.
For reducing of memory usege we replaced XSSFWorkbook by SXSSFWorkbook.
After that we have next exception.

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.getFont2D(Font.java:497)
    at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2250)
    at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469)
    at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530)
    at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
    at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
    at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:705)
    at

How we understand that relates with missing fonts and AutoSizeColumnTracker in SXSSFSheet.

public SXSSFSheet(SXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException {
        this._workbook = workbook;
        this._sh = xSheet;
        this._writer = workbook.createSheetDataWriter();
        this.setRandomAccessWindowSize(this._workbook.getRandomAccessWindowSize());
        this._autoSizeColumnTracker = new AutoSizeColumnTracker(this);
    }

This constructor has initialization of AutoSizeColumnTracker.
AutoSizeColumnTracker calculates defaultCharWidth.

Why does SXSSFWorkbook need in AutoSizeColumnTracker by default?
How can we disable that or maybe set custom defaultCharWidth without calculation?
Comment 1 Dominik Stadler 2021-04-27 05:45:40 UTC
It seems there is currently no way to avoid this dependency on some fonts being available.

We can review this in the future to see if there is a way to handle this more gracefully, maybe by catching and logging the exception with a fallback column width.

Patches highly welcome!
Comment 2 Andreas Beeker 2021-04-27 05:53:45 UTC
what is the security implications of having no fonts?
would it be compromised if we (try to) register a default font in the case we don't find any fonts?