Linux FontConfig坑记: sun.awt.FontConfiguration.getVersion

问题描述:

在使用阿里easyexcel框架做导出功能时,后台出现了NullPointerException异常,异常日志:

java.lang.NullPointerException: null
  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.(SunFontManager.java:376)
  at sun.awt.FcFontManager.(FcFontManager.java:35)
  at sun.awt.X11FontManager.(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:495)
  at java.awt.Font.canDisplayUpTo(Font.java:2080)
  at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
  at java.awt.font.TextLayout.(TextLayout.java:531)
  at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:275)
  at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.(AutoSizeColumnTracker.java:117)
  at org.apache.poi.xssf.streaming.SXSSFSheet.(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.alibaba.excel.util.WorkBookUtil.createSheet(WorkBookUtil.java:66)
  at com.alibaba.excel.context.WriteContextImpl.createSheet(WriteContextImpl.java:187)
  at com.alibaba.excel.context.WriteContextImpl.initSheet(WriteContextImpl.java:167)
  at com.alibaba.excel.context.WriteContextImpl.currentSheet(WriteContextImpl.java:114)
  at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:56)
  at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:161)
  at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:146)

从日志中看到,导出Excel应该是用到了AWT包中的字体相关到服务,这个需要Linux操作系统中存在有FontConfig控件。

解决方案

修改docker文件,增加以下配置:

RUN yum -y install fontconfig
RUN fc-cache --forc

重启服务,搞定!

你可能感兴趣的:(Linux FontConfig坑记: sun.awt.FontConfiguration.getVersion)