From: Javen O'Neal Date: Wed, 18 Oct 2017 14:29:56 +0000 (+0000) Subject: cleanup for r1812475: avoid NPEs from string.isEmpty() X-Git-Tag: REL_4_0_0_FINAL~430 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb854a6f340acd3d1f78b8b6be708d69b35162a8;p=poi.git cleanup for r1812475: avoid NPEs from string.isEmpty() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1812520 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 923f36f88c..3dac34b6cd 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -163,7 +163,8 @@ public class XSSFExportToXml implements Comparator{ mapCellOnNode(cell,currentNode); //remove nodes which are empty in order to keep the output xml valid - if (currentNode.getTextContent().isEmpty() && currentNode.getParentNode() != null) { + // FIXME: what should be done if currentNode.getTextContent() is null? + if ("".equals(currentNode.getTextContent()) && currentNode.getParentNode() != null) { currentNode.getParentNode().removeChild(currentNode); } } @@ -467,7 +468,8 @@ public class XSSFExportToXml implements Comparator{ // Note: we expect that all the complex types are defined at root level Node complexTypeNode = null; - if (!complexTypeName.isEmpty()) { + // FIXME: what should be done if complexTypeName is null? + if (!"".equals(complexTypeName)) { complexTypeNode = getComplexTypeNodeFromSchemaChildren(xmlSchema, null, complexTypeName); } @@ -483,8 +485,7 @@ public class XSSFExportToXml implements Comparator{ NodeList list = localComplexTypeRootNode.getChildNodes(); String complexTypeName = ""; - for(int i=0; i< list.getLength();i++) { - Node node = list.item(i); + for(final Node node : list) { if ( node instanceof Element && "element".equals(node.getLocalName())) { Node nameAttribute = getNameOrRefElement(node); if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {