Bug 59678

Summary: Write to a closed workbook
Product: POI Reporter: Jürgens <hartmut_juergens>
Component: SS CommonAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 3.15-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on: 59634    
Bug Blocks:    

Description Jürgens 2016-06-09 09:03:42 UTC
This code fragment raises an
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

File file = new File(...);
Workbook workbook = WorkbookFactory.create(file, "", false);
workbook.close();
File outfile = new File(...);
FileOutputStream outputStream = new FileOutputStream(outfile);
// exception in following line
workbook.write(outputStream);
Comment 1 Dominik Stadler 2016-06-09 09:40:07 UTC
I think this is more or less a duplicate of Bug 59634 where we discuss the exact contract of the close(). The discussion there currently tends to state "do not use the Workbook after closing" which is consistent with many other Java classes that implement the Closeable interface.

So you can easily fix this by deferring the close() call to after the Workbook is written out.

Bug 59634 might also adjust the code to provide a more meaningful error message.

*** This bug has been marked as a duplicate of bug 59634 ***