alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
31.96k stars 7.49k forks source link

数据写入CSV文件异常:Can not close IO #3769

Open ytt719 opened 4 months ago

ytt719 commented 4 months ago

异常出现的case是输出文件格式为CSV,但是如果实际代码执行过程没有数据写入到CSV文件,则在执行excelWrite.finish()时会报上述异常;

完整的异常堆栈: com.alibaba.excel.exception.ExcelGenerateException: Can not close IO. at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:420) at com.alibaba.excel.write.ExcelBuilderImpl.finish(ExcelBuilderImpl.java:99) at com.alibaba.excel.ExcelWriter.finish(ExcelWriter.java:143) at com.alipay.xxxxx.biz.bill.impl.QueryBillServiceImpl.queryBill(QueryBillServiceImpl.java:116) at com.alipay.xxxxx.biz.distributedtask.service.QueryBillDistributedTaskService.dispatchTasks(QueryBillDistributedTaskService.java:101) at com.alipay.xxxxx.biz.task.ScheduledJob.onApplicationEvent(ScheduledJob.java:31) at com.alipay.xxxxx.biz.task.ScheduledJob.onApplicationEvent(ScheduledJob.java:21) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:940) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) at com.alipay.xxxxx.bootstrap.BootstrapApplication.main(BootstrapApplication.java:38) Caused by: java.lang.NullPointerException: null at com.alibaba.excel.metadata.csv.CsvWorkbook.write(CsvWorkbook.java:247) at com.alibaba.excel.context.WriteContextImpl.finish(WriteContextImpl.java:381) ... 18 common frames omitted

ytt719 commented 4 months ago

easyexcel版本:3.3.4, poi版本:5.2.2

chauncyAAA commented 4 months ago

easyexcel版本:3.2.1,没有这个问题