Bug 62576 - autoSizeColumn columns is throwing null pointer exception
Summary: autoSizeColumn columns is throwing null pointer exception
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-27 14:37 UTC by jp
Modified: 2018-12-22 17:38 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jp 2018-07-27 14:37:39 UTC
doing:

sheet.autoSizeColumn(i);

java.lang.NullPointerException
        at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
        at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
        at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
        at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
        at sun.font.SunFontManager$2.run(SunFontManager.java:431)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.<init>(SunFontManager.java:376)
        at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
        at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
        at java.awt.Font.getFont2D(Font.java:491)
        at java.awt.Font.canDisplayUpTo(Font.java:2060)
        at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
        at java.awt.font.TextLayout.<init>(TextLayout.java:531)
        at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:275)
        at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:250)
        at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:235)
        at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:549)
        at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:531)
Comment 1 PJ Fanning 2018-07-27 20:43:09 UTC
Could you provide more details? A sample document, code to reproduce etc.?
Comment 2 Nick Burch 2018-09-05 07:06:35 UTC
This error is coming from a core bit of the JVM, so I don't think there's much Apache POI can do here...

My best guess is either you have a broken/buggy JVM, and need to upgrade it, or you have a broken set of True Type Fonts installed on your machine.

Make sure you have the latest version of the JVM installed, and if the problem remains, follow instructions for your chosen Linux distro to install / re-install the fonts + make the JVM able to see them.
Comment 3 jp 2018-09-07 09:33:17 UTC
I couldn't reproduce it in my machine (opensuse leap 42.2) with my Oracle JDK 1.8 update 181. 

This excepcetion it's occurring in docker, running on container: openjdk:8-jdk-alpine. 

(In reply to Nick Burch from comment #2)
> This error is coming from a core bit of the JVM, so I don't think there's
> much Apache POI can do here...
> 
> My best guess is either you have a broken/buggy JVM, and need to upgrade it,
> or you have a broken set of True Type Fonts installed on your machine.
> 
> Make sure you have the latest version of the JVM installed, and if the
> problem remains, follow instructions for your chosen Linux distro to install
> / re-install the fonts + make the JVM able to see them.

ohhh I see. 

I couldn't reproduce it in my OS (OpenSuSE leap 4.2) with Oracle JDK 1.8 u181. 

this is occurring only in docker, container: openjdk:8-jdk-alpine

I hope you can catch it now. I guess will be checking null pointer in FontConfiguration.java:1264 , right ?
Comment 4 PJ Fanning 2018-09-07 15:36:19 UTC
Looks like https://github.com/docker-library/openjdk/issues/73 -
There is a suggested workaround:

apt-get -y --no-install-recommends install libfontconfig1

https://github.com/docker-library/openjdk/pull/48
Comment 5 Dominik Stadler 2018-12-22 17:38:56 UTC
I don't think we can fix anything in Apache POI, a workaround has been proposed, thus resolving this here.