Bug 59427: Add a check to better report cases when a document is already closed.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1744306 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
df72dbfbed
commit
0c78005743
@ -196,6 +196,10 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart implements Close
|
||||
//save extended and custom properties
|
||||
getProperties().commit();
|
||||
|
||||
getPackage().save(stream);
|
||||
OPCPackage pkg = getPackage();
|
||||
if(pkg == null) {
|
||||
throw new IOException("Cannot write data, document seems to have been closed already");
|
||||
}
|
||||
pkg.save(stream);
|
||||
}
|
||||
}
|
||||
|
@ -1090,4 +1090,21 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||
//wb = new XSSFWorkbook(OPCPackage.open(file));
|
||||
//assertCloseDoesNotModifyFile(filename, wb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseBeforeWrite() throws IOException {
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
wb.createSheet("somesheet");
|
||||
|
||||
// test what happens if we close the Workbook before we write it out
|
||||
wb.close();
|
||||
|
||||
try {
|
||||
XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
fail("Expecting IOException here");
|
||||
} catch (RuntimeException e) {
|
||||
// expected here
|
||||
assertTrue("Had: " + e.getCause(), e.getCause() instanceof IOException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user