Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8066690

JAXB unmarshal fails due to XSD validation failure

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P2 P2
    • None
    • 9
    • xml
    • b39
    • 9
    • generic
    • generic

      JDK9b40 fails to unmarshal some XML files against corresponding XML Schema. Please notice that JAXP parses XML files in questions and validates them against corresponding XSD successfully - please see testJaxp method in Test7.java withing attached minimized.zip.

      For instance, let's consider following pair of XSD and XML:

      particlesA011.xsd:

          <?xml version="1.0"?>
          <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
              <xsd:element name="doc">
                  <xsd:complexType>
                      <xsd:choice>
                          <xsd:element name="elem" type="elem"/>
                      </xsd:choice>
                  </xsd:complexType>
              </xsd:element>
              <xsd:complexType name="elem">
                  <xsd:choice minOccurs="2" maxOccurs="3">
                      <xsd:element name="e1"/>
                      <xsd:element name="e2"/>
                  </xsd:choice>
              </xsd:complexType>
          </xsd:schema>

      particlesA011.xml:

          <?xml version="1.0"?>
          <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="particlesA011.xsd">
              <elem>
                  <e2/>
                  <e2/>
                  <e2> test </e2>
              </elem>
          </doc>

      when umarshaling following exception is thrown:

          javax.xml.bind.UnmarshalException
           - with linked exception:
          [org.xml.sax.SAXParseException; systemId:
          file:/D:/xmlworks/smalls/src2/particlesA011.xml; lineNumber: 6;
          columnNumber: 7; cvc-complex-type.2.4.d: Invalid content was found
          starting with element 'e2'. No child element is expected at this
          point.]
              at
      javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:335)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:563)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:249)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:214)
              at
      javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
              at
      javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:162)
              at
      javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:171)
              at Test7.test(Test7.java:138)
              at Test7.main(Test7.java:104)
          Caused by: org.xml.sax.SAXParseException; systemId:
          file:/D:/xmlworks/smalls/src2/particlesA011.xml; lineNumber: 6;
          columnNumber: 7; cvc-complex-type.2.4.d: Invalid content was found
          starting with element 'e2'. No child element is expected at this
          point.
              at
      com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
              at
      com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
              at
      com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
              at
      com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
              at
      com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
              at
      com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:497)
              at
      com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3574)
              at
      com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1974)
              at
      com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:815)
              at
      com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:569)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:86)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:153)
              at
      com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:508)
              at
      com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:378)
              at
      com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2790)
              at
      com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
              at
      com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
              at
      com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
              at
      com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:876)
              at
      com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
              at
      com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:140)
              at
      com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1212)
              at
      com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
              at
      com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:243)
              ... 6 more

      This seems to be JDK bug because the XML above looks like valid document against XSD presented above. The type of "<xsd:element name="e2"/>" is anyType according to W3C spec [1]:

          An <element> with no referenced or included type definition will
          correspond to an element declaration which has the same type
          definition as the head of its substitution group if it identifies
          one, /_*otherwise the ·ur-type definition·*_/.
          ...
          [Definition:] A distinguished complex type definition, the
          ur-type definition, whose name is /_*anyType*_/ in the XML Schema
          namespace, is present in each ·XML Schema·, serving as the root of
          the type definition hierarchy for that schema.

      The minimized testcase is attached; it contains 12 cases including the presented above which fail. In order to run the minimized tests:
      1. Create some directory on Windows platform;
      2. unzip the attached archive to the directory created at step 1;
      3. modify unzipped test7-run.bat by changing JAVA_DIR variable value in order it to contain the path to JDK installation folder;
      4. run test7-run.bat;
      5. after running each created directory will contain err.txt with thrown exception stack trace printed.

      [1] http://www.w3.org/TR/xmlschema-1/

        1. jdk8066690.tar.gz
          19 kB
          Roman Grigoriadi
        2. wildL006_wildL006.jtr
          3 kB
          Prabushankar Chinnasamy
        3. wildL006_wildL006.jtr
          3 kB
          Prabushankar Chinnasamy

            aefimov Aleksej Efimov
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: