poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1744306 - in /poi/trunk/src/ooxml: java/org/apache/poi/POIXMLDocument.java testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Date Tue, 17 May 2016 19:08:34 GMT
Author: centic
Date: Tue May 17 19:08:34 2016
New Revision: 1744306

URL: http://svn.apache.org/viewvc?rev=1744306&view=rev
Log:
Bug 59427: Add a check to better report cases when a document is already closed.

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=1744306&r1=1744305&r2=1744306&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Tue May 17 19:08:34 2016
@@ -196,6 +196,10 @@ public abstract class POIXMLDocument ext
         //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);
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1744306&r1=1744305&r2=1744306&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Tue
May 17 19:08:34 2016
@@ -1090,4 +1090,21 @@ public final class TestXSSFWorkbook exte
         //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);
+		}
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message