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 about 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
Actions #1

Updated by Michael Kay about 2 years ago

Thanks for reporting it and supplying the repro.

Actions #2

Updated by Michael Kay about 2 years ago

  • Category set to Schema conformance
  • Status changed from New to In Progress
  • Assignee set to Michael Kay

It seems that the problem occurs when an invalid value participates in a uniqueness constraint. We're getting an internal exception when we evaluate the constraint because we try to convert the value to an integer to compare it with other integers participating in the same constraint, and we assume at this stage that the value is valid, but it isn't.

Actions #3

Updated by Michael Kay about 2 years ago

I tried to handle this by substituting an EmptyAtomicSequence in the constraint, but this fails in SelectorWatch.ValueEntry.hash() because EmptyAtomicSequence.getSchemaComparable() returns null -- which feels wrong, but perhaps it's otherwise unused.

Using AtomicArray.EMPTY_ATOMIC_ARRAY does the trick.

Not sure why we have both EmptyAtomicSequence and AtomicArray.EMPTY_ATOMIC_ARRAY -- it seems unnecessary duplication -- but to tidy things up we can implement EmptyAtomicSequence.getSchemaComparable() as AtomicArray.EMPTY_ATOMIC_ARRAY.getSchemaComparable().

Actions #4

Updated by Michael Kay about 2 years ago

Looks like the same problem needs fixing on several other paths:

  • Attribute content as well as element content

  • Namespace-sensitive (QName-valued) content

  • List-valued content

Actions #5

Updated by Michael Kay about 2 years ago

  • Subject changed from Validation fails with SAXException *after* successfully reporting a schema error to Invalid values for a field with a uniqueness constraint cause validator to crash after reporting the first error.
Actions #6

Updated by Michael Kay about 2 years ago

  • Status changed from In Progress to Resolved
  • Applies to branch 11, trunk added
  • Fix Committed on Branch 10, trunk added

Added unit tests to jaxptest/ValidationTest

Actions #7

Updated by O'Neil Delpratt about 2 years ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 11.1 added
  • Platforms .NET added

Bug fix applied in the Saxon 11.1 release.

Actions #8

Updated by O'Neil Delpratt about 2 years ago

Leaving bug as resolved until fix applied to the Saxon 10 maintenance release.

Actions #9

Updated by Debbie Lockett about 2 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 10.7 added
  • Fixed in Maintenance Release deleted (11.1)

Bug fix applied in the Saxon 10.7 maintenance release.

Actions #10

Updated by Debbie Lockett about 2 years ago

  • Fixed in Maintenance Release 11.1 added

Please register to edit this issue

Also available in: Atom PDF