Bug #4744

Schema validation errors not reported to ErrorListener

Added by Marek Skorek about 1 month ago. Updated 29 days ago.

In Progress
Schema conformance
Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:



Our regression test detected a bug in Saxon 9.9 which was fixed in Saxon 9.7.21 version. I attached a test XML file and XSD to validate this file against.

Please feel free to add this test case to Saxon test suites.

UniqueKeyBug.xml (117 Bytes) UniqueKeyBug.xml Test XML file Marek Skorek, 2020-09-22 10:31
UniqueKeyBug.xsd (1.1 KB) UniqueKeyBug.xsd XSD to validate test file against Marek Skorek, 2020-09-22 10:31


#1 Updated by Marek Skorek about 1 month ago

This was previously reported in

#2 Updated by Michael Kay about 1 month ago

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

In both and 10.2 I'm seeing a validation error here:

Validation error on line 2 column 69 of UniqueKeyBug.xml:
  Non-unique value found for constraint uniqueKey: ("A", "B", "C", "D")
  See clause 4.1

which is the outcome I would expect. If you aren't seeing an error, could you provide more details of how you are running the validation, please?

#3 Updated by Marek Skorek 30 days ago

Hello Micheal, thank you for your response.

I can confirm that running validation from command line produces validation error as expected.

After further investigation I found that real source of our problem is that version doesn't notify error listner (set up by method setErrorListener on SchemaValidator instance) as opposed to version where error method was invoked with following exception

org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 33; Non-unique value found for constraint uniqueKey: ("A", "B", "C", "D")
Caused by: ValidationException: Non-unique value found for constraint uniqueKey: ("A", "B", "C", "D")

Do you have any suggestions?

#4 Updated by Michael Kay 29 days ago

OK, I'll try and see if I can reproduce it with a SchemaValidator. 9.9 introduced a new mechanism for reporting invalidity, but setErrorListener() should still work.

#5 Updated by Michael Kay 29 days ago

Sorry, can't reproduce the problem. The following JUnit test works as expected (on both 9.9 and 10.2):

public void testErrorListenerBug4744() {
        final List<TransformerException> errorList = new ArrayList<>();
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(ConfigTest.DATA_DIR + "sandpit/validation.out");
            Processor proc = new Processor(true);
            SchemaManager sm = proc.getSchemaManager();
            StreamSource source_xsd = new StreamSource(new File("...../UniqueKeyBug.xsd"));
            StreamSource source_xml = new StreamSource(new File("...../UniqueKeyBug.xml"));
            ErrorListener listener = new ErrorListener() {
                public void error(TransformerException exception) {

                public void fatalError(TransformerException exception) throws TransformerException {
                    throw exception;

                public void warning(TransformerException exception) {

            SchemaValidator sv = sm.newSchemaValidator();

            Serializer serializer = proc.newSerializer();
            serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
            serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");

            fail("Invalidity not detected") ;

        } catch (SaxonApiException sapie) {
            try {
            } catch (IOException ee) {
            assertEquals(1, errorList.size());
        } catch (Exception e) {

Perhaps you're expecting it to be notified to the fatalError() callback?

#6 Updated by Marek Skorek 29 days ago

We are not using ErrorListener directly, instead we use our implementation of ErrorHandler wrapped in SchemaFactoryImpl.ErrorListenerWrappingErrorHandler, so you are right that ErrorListener is notified about validation error, but this particular implementation doesn't proppagate this error to our ErrorHandler.

For some reason incoming ValidationException is marked as hasBeenReported=true (in our case this behaviour is the same regardless of library version), but in new library version there is additional check in ErrorListenerWrappingErrorHandler.error method

if (exception instanceof XPathException) {
    if (((XPathException)exception).hasBeenReported()) {



preventing ErrorHandler invocation.

#7 Updated by Michael Kay 29 days ago

  • Subject changed from Unique key validation error which was fixed in 9.7.21 is alive in 9.9 again to Schema validation errors not reported to ErrorListener

Looks as if you've identified the problem, now I just have to work out a fix.

Please register to edit this issue

Also available in: Atom PDF