liaochong / myexcel

MyExcel, a new way to operate excel!
https://github.com/liaochong/myexcel/wiki
Apache License 2.0
1.66k stars 325 forks source link

使用DefaultExcelReader导入遇到错误时报java.lang.NullPointerException #419

Open fcmfcm01 opened 7 months ago

fcmfcm01 commented 7 months ago

Bug描述 版本:4.5.0 com.github.liaochong.myexcel.core.context.ReadContext#readConfig 未初始化,导致当Excel导入时对错误信息的处理失败。

Bug复现 按如下步骤复现(Steps to reproduce the behavior):

  1. 按照导入示例准备一份导入数据和POJO,其中导入数据中存在数字转换异常,例如,POJO中a 变量为Double型,数据中对应列数据为“字符”
  2. 使用DefaultExcelReader,导入刚才的数据, 得到下面的异常:
    java.lang.NullPointerException: null
    at com.github.liaochong.myexcel.core.converter.ReadConverterContext.convert(ReadConverterContext.java:149)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.lambda$instanceObj$18(DefaultExcelReader.java:432)
    at java.util.HashMap.forEach(HashMap.java:1289)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.instanceObj(DefaultExcelReader.java:417)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.getDataFromFile(DefaultExcelReader.java:329)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.doRead(DefaultExcelReader.java:202)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.read(DefaultExcelReader.java:183)
    at com.github.liaochong.myexcel.core.DefaultExcelReader.read(DefaultExcelReader.java:179)

期望的结果 Boolean toContinue = readContext.readConfig.exceptionFunction.apply(e, readContext); 语句能够正常执行

liaochong commented 7 months ago

请提供下版本,另外如果不导入图片,建议使用SaxExcelReader