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

Facet Validation Fails while Serializing with CDATA elements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 2.10.0
    • None
    • None

    Description

      While marshalling a document with JAXB, I get the following error: [org.xml.sax.SAXParseException: cvc-maxLength-valid: Value '<![CDATA[foo]]>' with length = '15' is not facet-valid with respect to maxLength '3' for type '#AnonType_test'.]
      The document itself is valid when I parse it from a file. I tried it with DOM and SAX.

      I attached a simple maven test project. Executing the main class TestJaxbValidate creates the following exception.

      Exception in thread "main" javax.xml.bind.MarshalException
       - with linked exception:
      [org.xml.sax.SAXParseException: cvc-maxLength-valid: Value '<![CDATA[foo]]>' with length = '15' is not facet-valid with respect to maxLength '3' for type '#AnonType_test'.]
      	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)
      	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
      	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
      	at TestJaxbValidate.main(TestJaxbValidate.java:23)
      Caused by: org.xml.sax.SAXParseException: cvc-maxLength-valid: Value '<![CDATA[foo]]>' with length = '15' is not facet-valid with respect to maxLength '3' for type '#AnonType_test'.
      	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
      	at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
      	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
      	at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
      	at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.endElement(Unknown Source)
      	at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
      	at com.sun.xml.bind.v2.runtime.output.SAXOutput.endTag(SAXOutput.java:132)
      	at com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.endTag(XmlOutputAbstractImpl.java:124)
      	at com.sun.xml.bind.v2.runtime.output.ForkXmlOutput.endTag(ForkXmlOutput.java:91)
      	at com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl$Element.endElement(NamespaceContextImpl.java:504)
      	at com.sun.xml.bind.v2.runtime.XMLSerializer.endElement(XMLSerializer.java:315)
      	at com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement(XMLSerializer.java:345)
      	at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$StringImplImpl.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:1052)
      	at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$StringImplImpl.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:1031)
      	at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.writeLeafElement(TransducedAccessor.java:256)
      	at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:129)
      	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:161)
      	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:131)
      	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:333)
      	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:340)
      	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:76)
      	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
      	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
      	... 3 more

      Attachments

        1. testproject.zip
          5 kB
          Michael Ernst

        Activity

          People

            Unassigned Unassigned
            michaelernst Michael Ernst
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: