3

The error occurs during initilizing of a org.apache.poi.ss.usermodel.Sheet Can I fix this to prevent failure on OpenJdk on Linux.

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.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
        at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:79)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:656)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:677)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:83)
        at com.jthink.songkong.reports.spreadsheet.Worksheet.<init>(Worksheet.java:24)

Update

Based on comment no font files found in lib

[root@N1-ZS10 lib]# ls -l

total 70948
drwxrwxr-x 4 root root     4096 Mar 29 15:09 aarch32
drwxrwxr-x 2 root root     4096 Mar 29 11:28 applet
-rw-rw-r-- 1 root root     2375 Mar 29 11:28 calendars.properties
-rw-rw-r-- 1 root root  3135391 Mar 29 11:28 charsets.jar
-rw-rw-r-- 1 root root    84311 Mar 29 11:28 classlist
drwxrwxr-x 2 root root     4096 Mar 29 15:09 cmm
-rw-rw-r-- 1 root root     5916 Mar 29 11:28 content-types.properties
-r--r--r-- 1 root root     4122 Mar 29 11:28 currency.data
drwxrwxr-x 2 root root     4096 Mar 29 15:09 ext
-rw-rw-r-- 1 root root     3901 Mar 29 11:28 flavormap.properties
-rw-rw-r-- 1 root root    14959 Mar 29 11:28 hijrah-config-umalqura.properties
drwxrwxr-x 3 root root     4096 Mar 29 15:08 images
-rw-rw-r-- 1 root root    95642 Mar 29 11:28 jce.jar
-rwxrwxr-x 1 root root    15917 Mar 29 11:28 jexec
-rw-rw-r-- 1 root root   647046 Mar 29 11:28 jsse.jar
-rw-rw-r-- 1 root root     4226 Mar 29 11:28 jvm.hprof.txt
-rw-rw-r-- 1 root root     2455 Mar 29 11:28 logging.properties
drwxrwxr-x 2 root root     4096 Mar 29 15:09 management
-rw-rw-r-- 1 root root      381 Mar 29 11:28 management-agent.jar
-rw-rw-r-- 1 root root     1922 Mar 29 11:28 meta-index
-rw-rw-r-- 1 root root     4464 Mar 29 11:28 net.properties
-rw-rw-r-- 1 root root     3793 Mar 29 11:28 psfont.properties.ja
-rw-rw-r-- 1 root root    11390 Mar 29 11:28 psfontj2d.properties
-rw-rw-r-- 1 root root  3509545 Mar 29 11:28 resources.jar
-rw-rw-r-- 1 root root 64833198 Mar 29 11:28 rt.jar
drwxrwxr-x 2 root root     4096 Mar 29 15:08 security
-rw-rw-r-- 1 root root     1210 Mar 29 11:28 sound.properties
-rw-rw-r-- 1 root root   104311 Mar 29 11:28 tzdb.dat
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • Install the missing fonts? – Gagravarr Mar 29 '17 at 17:33
  • 1
    @Gagravarr what are the missing fonts though ? – Paul Taylor Mar 29 '17 at 19:53
  • Whatever ones you're using in your spreadsheet presumably... – Gagravarr Mar 29 '17 at 22:50
  • 4
    Can it be that there is only `openjdk-8-jre-headless` installed? That `JRE` does not provide fonts since it does not deal with `X11`. Try installing `openjdk-8-jre`. See http://stackoverflow.com/questions/30626136/cannot-load-font-in-jre-8. – Axel Richter Mar 30 '17 at 03:55
  • @AxelRichter I'm not sure its a custom build for arm provided by 3rd party (it has filename jre-8u121+1-linux-aarch32-vfp-hflt.tar.gz), however my code has references to gui classes and that doesnt cause it to fail, whereas a 'compact' version did. Does headless version still contain references to gui classes ? – Paul Taylor Mar 30 '17 at 10:11
  • No a headless JRE will not refer GUI classes. But if this is not really `openjdk-8-jre` but a customized JRE provided from third party, then I suspect that this JRE lacks something. – Axel Richter Mar 30 '17 at 11:30
  • @AxelRichter I have checked it is same as openjdk, the only difference is the JIT, which is an open-source aarch32 (ARMv7) JIT contributed to OpenJDK by Azul. Maybe this isa bug with poi relying on a specific font ? – Paul Taylor Mar 30 '17 at 19:42
  • 2
    According to the error (`sun.awt.FontConfiguration.getVersion` throws NullPointerException in line `return getString(head[INDEX_version]);`) , `head` must be `null`. That can only occur if a `FontConfigFile` was not found in `javaHome/lib`. So please check wheter files `/lib/fontconfig.properties.*` exists in your openjdk-jre java Home directory. – Axel Richter Mar 31 '17 at 10:14
  • @AxelRichter you are correct there is no such file on any font related file. – Paul Taylor Mar 31 '17 at 15:03
  • @AxelRichter but then ive just done a standard installation an ubuntu machine and checked java-8-openjdk-amd64/jre/lib and that has no fontconfig.properties file either !? – Paul Taylor Mar 31 '17 at 15:24
  • @AxelRichter Openjdk depends on system fonts of which i had none installed, but I found that creating a fonts folder in the jre's lib folder and just copyig some fonts into it fixed the problem - http://stackoverflow.com/questions/43144517/where-are-fonts-defined-installed-for-openjdk-java-on-linux – Paul Taylor Mar 31 '17 at 19:35

2 Answers2

1

Just for completeness I add here the answer of Paul Taylor:

Openjdk depends on system fonts of which i had none installed, but I found that creating a fonts folder in the jre's lib folder and just copyig some fonts into it fixed the problem

see here: stackoverflow.com/questions/43144517/…

pme
  • 14,156
  • 3
  • 52
  • 95
1

Just add the following in your Dockerfiel

RUN apk add --no-cache fontconfig ttf-dejavu

Or if it is machine, execute the following

apk add --no-cache fontconfig ttf-dejavu
craftsmannadeem
  • 2,665
  • 26
  • 22