aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java16
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java24
-rwxr-xr-xtest-data/spreadsheet/noSharedStringTable.xlsxbin0 -> 7820 bytes
3 files changed, 33 insertions, 7 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
index 5263473bca..24e2c649d3 100644
--- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
@@ -132,13 +132,15 @@ public class ReadOnlySharedStringsTable extends DefaultHandler {
* @throws ParserConfigurationException
*/
public void readFrom(InputStream is) throws IOException, SAXException {
- InputSource sheetSource = new InputSource(is);
- try {
- XMLReader sheetParser = SAXHelper.newXMLReader();
- sheetParser.setContentHandler(this);
- sheetParser.parse(sheetSource);
- } catch(ParserConfigurationException e) {
- throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
+ if (is.available() > 0) {
+ InputSource sheetSource = new InputSource(is);
+ try {
+ XMLReader sheetParser = SAXHelper.newXMLReader();
+ sheetParser.setContentHandler(this);
+ sheetParser.parse(sheetSource);
+ } catch(ParserConfigurationException e) {
+ throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
+ }
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
index c4690369b9..ad8470baba 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
@@ -20,12 +20,16 @@
package org.apache.poi.xssf.eventusermodel;
import junit.framework.TestCase;
+
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xssf.model.SharedStringsTable;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+import org.xml.sax.SAXException;
+import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;
@@ -55,4 +59,24 @@ public final class TestReadOnlySharedStringsTable extends TestCase {
}
}
+
+ public void testEmptySSTOnPackageObtainedViaWorkbook() throws Exception {
+ XSSFWorkbook wb = new XSSFWorkbook(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
+ OPCPackage pkg = wb.getPackage();
+ assertEmptySST(pkg);
+ wb.close();
+ }
+
+ public void testEmptySSTOnPackageDirect() throws Exception {
+ OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
+ assertEmptySST(pkg);
+ }
+
+ private void assertEmptySST(OPCPackage pkg) throws IOException, SAXException {
+ ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg);
+ assertEquals(0, sst.getCount());
+ assertEquals(0, sst.getUniqueCount());
+ assertNull(sst.getItems()); // same state it's left in if fed a package which has no SST part.
+ }
+
}
diff --git a/test-data/spreadsheet/noSharedStringTable.xlsx b/test-data/spreadsheet/noSharedStringTable.xlsx
new file mode 100755
index 0000000000..49f14658d0
--- /dev/null
+++ b/test-data/spreadsheet/noSharedStringTable.xlsx
Binary files differ