Bug #5208
closedInvalid values for a field with a uniqueness constraint cause validator to crash after reporting the first error.
100%
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
Updated by Michael Kay almost 3 years ago
Thanks for reporting it and supplying the repro.
Updated by Michael Kay almost 3 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.
Updated by Michael Kay almost 3 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()
.
Updated by Michael Kay almost 3 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
Updated by Michael Kay almost 3 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.
Updated by Michael Kay almost 3 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
Updated by O'Neil Delpratt almost 3 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.
Updated by O'Neil Delpratt almost 3 years ago
Leaving bug as resolved until fix applied to the Saxon 10 maintenance release.
Updated by Debbie Lockett over 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.
Updated by Debbie Lockett over 2 years ago
- Fixed in Maintenance Release 11.1 added
Please register to edit this issue