From 2a08a1dd10de5236fb674d914ab3523304d66ad1 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 8 Dec 2013 08:35:20 +0000 Subject: [PATCH] Bug 55850: fix NullPointerException during extraction from XSSF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549007 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/extractor/XSSFExportToXml.java | 6 +-- .../xssf/extractor/TestXSSFExportToXML.java | 38 ++++++++++++++++++ test-data/spreadsheet/55850.xlsx | Bin 0 -> 12464 bytes 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test-data/spreadsheet/55850.xlsx diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 2e6b90242..a6e1a2785 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -41,11 +41,11 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell; import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType; @@ -476,7 +476,7 @@ public class XSSFExportToXml implements Comparator{ if (!"".equals(complexTypeName)) { NodeList complexTypeList = xmlSchema.getChildNodes(); for(int i=0; i< complexTypeList.getLength();i++) { - Node node = list.item(i); + Node node = complexTypeList.item(i); if ( node instanceof Element) { if (node.getLocalName().equals("complexType")) { Node nameAttribute = node.getAttributes().getNamedItem("name"); @@ -504,4 +504,4 @@ public class XSSFExportToXml implements Comparator{ } return complexTypeNode; } -} +} \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 3bbb861f4..cb70b358f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -176,4 +176,42 @@ public final class TestXSSFExportToXML extends TestCase { } } } + + public void test55850ComplexXmlExport() throws Exception { + + XSSFWorkbook wb = XSSFTestDataSamples + .openSampleWorkbook("55850.xlsx"); + + for (POIXMLDocumentPart p : wb.getRelations()) { + + if (!(p instanceof MapInfo)) { + continue; + } + MapInfo mapInfo = (MapInfo) p; + + XSSFMap map = mapInfo.getXSSFMapById(2); + + assertNotNull("XSSFMap is null", map); + + XSSFExportToXml exporter = new XSSFExportToXml(map); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + exporter.exportToXML(os, true); + String xmlData = os.toString("UTF-8"); + + assertNotNull(xmlData); + assertTrue(!xmlData.equals("")); + + String a = xmlData.split("")[1].split("")[0].trim(); + String b = a.split("")[1].split("")[0].trim(); + String c = b.split("")[1].split("")[0].trim(); + String d = c.split("")[1].split("")[0].trim(); + String e = d.split("")[1].split("")[0].trim(); + + String euro = e.split("")[1].split("")[0].trim(); + String chf = e.split("")[1].split("")[0].trim(); + + assertEquals("15", euro); + assertEquals("19", chf); + } + } } diff --git a/test-data/spreadsheet/55850.xlsx b/test-data/spreadsheet/55850.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..ea8dc0e39996dbcfad6f50e3368cf2adb3a35871 GIT binary patch literal 12464 zcmeHtWmFtnv-aTb?hrJ%1`Y1+!3hot?hqsl?(XjHL4sQ#1b250PH_JwIq!RO4(Hsv z?yv99eS58$UOjuNx_j^Esj6L7iZT$8m;h)1EC2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