From: Dominik Stadler Date: Sun, 8 Dec 2013 08:35:20 +0000 (+0000) Subject: Bug 55850: fix NullPointerException during extraction from XSSF X-Git-Tag: REL_3_10_FINAL~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9484ef6f17137eca19415628e4151718f88a84c2;p=poi.git 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 --- 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 2e6b90242a..a6e1a2785a 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 3bbb861f42..cb70b358f8 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 0000000000..ea8dc0e399 Binary files /dev/null and b/test-data/spreadsheet/55850.xlsx differ