Project

Profile

Help

Bug #5208

closed

Invalid values for a field with a uniqueness constraint cause validator to crash after reporting the first error.

Added by Tuomas Blom over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Schema conformance
Sprint/Milestone:
-
Start date:
2022-01-17
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, trunk
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

When validating an XML file containing a non-integer string "1A" in an integer field, we discovered Saxon validation to exit abnormally with a SAXException. It seems that the field itself is validated successfully and an error is normally reported to the ErrorHandler, but a later endElement() processing fails and returns a ValidationException.

This is somehow related to the schema we are validating against: I can reproduce the problem by using the full schema, but when I tried to create a minimal schema with the same elements and restrictions, the validation completed normally.

The exception occurs when validating the "sequence" field, defined as follows:

<xs:element name="sequence" minOccurs="0">
    <xs:simpleType>
        <xs:restriction base="cus:numeric">
            <xs:minInclusive value="1"/>
            <xs:pattern value="[1-9][0-9]*"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

And the "cus:numeric" the restriction it is based on is:

<xs:simpleType name="numeric">
    <xs:restriction base="xs:integer"/>
</xs:simpleType>

We do not own the schema ourselves, so we cannot try to circumvent the problem by changing the schema.

I've attached a simple test program for reproducing the error. The package contains the full schema and a failing xml file. Consult the README file for compile & execute instructions.

Just in case it helps, here are the relevant parts from the stacktrace we get in production:

Caused by: org.xml.sax.SAXException: Cannot convert string "1A" to an integer
        at com.saxonica.ee.jaxp.ValidatorImpl.validate(ValidatorImpl.java:81) ~[Saxon-EE-10.6.jar:?]
        at javax.xml.validation.Validator.validate(Validator.java:124) ~[?:1.8.0_301]
        [...]
Caused by: net.sf.saxon.type.ValidationException: Cannot convert string "1A" to an integer
        at net.sf.saxon.type.ValidationFailure.makeException(ValidationFailure.java:406) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.type.ValidationFailure.asAtomic(ValidationFailure.java:432) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.validate.FieldChecker.endElement(FieldChecker.java:209) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.stream.watch.WatchManager.endElement(WatchManager.java:484) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.TeeOutputter.endElement(TeeOutputter.java:144) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.TeeOutputter.endElement(TeeOutputter.java:143) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:148) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.validate.SimpleContentValidator.endElement(SimpleContentValidator.java:251) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.validate.ValidationStack.endElement(ValidationStack.java:494) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:148) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:148) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.validate.AttributeInheritor.endElement(AttributeInheritor.java:62) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.PathMaintainer.endElement(PathMaintainer.java:62) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.DocumentValidator.endElement(DocumentValidator.java:78) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.ReceivingContentHandler.endElement(ReceivingContentHandler.java:570) ~[Saxon-EE-10.6.jar:?]
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) ~[xercesImpl-2.12.1.jar:2.12.1]
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.12.1.jar:2.12.1]
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.12.1.jar:2.12.1]
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[xercesImpl-2.12.1.jar:?]
        at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439) ~[Saxon-EE-10.6.jar:?]
        at net.sf.saxon.event.Sender.send(Sender.java:168) ~[Saxon-EE-10.6.jar:?]
        at com.saxonica.ee.jaxp.ValidatorImpl.validate(ValidatorImpl.java:73) ~[Saxon-EE-10.6.jar:?]
        at javax.xml.validation.Validator.validate(Validator.java:124) ~[?:1.8.0_301]
        [...]

Until this is fixed, we will have to catch SAXExceptions and treat them like validation errors.


Files

saxon-validator-bug-demo.zip (10.4 KB) saxon-validator-bug-demo.zip Test program for reproducing Tuomas Blom, 2022-01-17 23:31

Please register to edit this issue

Also available in: Atom PDF