https://issues.apache.org/bugzilla/show_bug.cgi?id=55864

            Bug ID: 55864
           Summary: NullPointerException:
                    XSSFImportFromXML.importFromXML() does not support
                    optional elements
           Product: POI
           Version: 3.9
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]

Created attachment 31102
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31102&action=edit
ZIP containing an XML Schema with optional element, an XML file that validates
against this schema and an Excel file with XML Maps using 'mapping.xsd'

Please see the contents of the zip file attached to this bug...

The XML Schema file 'mapping.xsd' contains an optional element:
 <xs:element name="OptionalRating" type="xs:decimal" minOccurs="0"/>

The XML file 'data.xml' validates successfully against 'mapping.xsd'. It does
not contain the element 'OptionalRating'.

Importing 'data.xml' into an Excel file with XML maps using 'mapping.xsd' with
XSSFImportFromXML.importFromXML(xmlInputString) fails with a
NullPointerException because the code assumes that all elements declared in the
XML Schema file must also be present in the XML data file (which is not
necessarily the case if elements are declared optional.

The exception occurs on the following code line in method
"XSSFImportFromXML.importFromXML(xmlInputString)":
 Node result = (Node) xpath.evaluate(xpathString, doc, XPathConstants.NODE);
 // result can be null with optional nodes!
 String textContent = result.getTextContent(); // NPE on 'result' access

A unit test to reproduce this exception could look like this:
 InputStream xlsxInput = getResourceAsStream("excelWithMapping.xlsx");
 InputStream xmlInput = getResourceAsStream("data.xml");
 String xml = IOUtils.toString(xmlInput);
 XSSFWorkbook wb = openWorkbook(xlsxInput);
 XSSFMap map = wb.getMapInfo().getXSSFMapByName("PersonInfoRoot_Map");
 XSSFImportFromXML importer = new XSSFImportFromXML(map);
 importer.importFromXML(xml); // throws NPE


Additional info:
- used POI version: 3.9
- used Excel version: 2010

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to