Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1589

NullPointerException when parsing an instance that has a XSD 1.0 schema with 'defaultOpenContent' element

    XMLWordPrintableJSON

Details

    Description

      If I parse the instance.xml file using the following java code, I get an NullPointerException. I tested on the xml-schema-1.1-dev branch.

      ---------Java code----------------------
      XMLReader parser = new org.apache.xerces.parsers.SAXParser();
      parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, true);
      parser.parse("file:/C:/instance.xml");
      --------------------------------------

      ----------------instance.xml------------------
      <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd"/>
      -------------------------------------------------------

      --------------------schema.xsd----------------
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:defaultOpenContent mode="suffix">
      <xs:any/>
      </xs:defaultOpenContent>

      <xs:element name="root"/>
      </xs:schema>
      --------------------------------------------------------

      -----------NullPointerException -------------------------------
      Exception in thread "main" java.lang.NullPointerException
      at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseOpenContent(XSDComplexTypeTraverser.java:268)
      at org.apache.xerces.impl.xs.traversers.XSDHandler.buildGlobalNameRegistries(XSDHandler.java:1481)
      at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:716)
      at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:644)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:3074)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2259)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:880)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:275)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:733)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
      at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:890)
      at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:813)
      at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
      at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1129)
      ---------------------------------------------------------------------------

      It seems that in the XSDHandlerXerces.buildGlobalNameRegistries(), the method XSDComplexTypeTraverser.traverseOpenContent(Element, XSDocumentInfo, SchemaGrammar, boolean) is called even if the current schema version is 1.0. For 1.0 this method should not be called.
      Also the XSAttributeCheckerXerces.checkAttributes(Element, boolean, XSDocumentInfo, boolean) method can return null in some cases, maybe you should check that the attributes array is not null before using it.

      Attachments

        Activity

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            octavian.nadolu Octavian Nadolu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: