Project

Profile

Help

Bug #5953

closed

JAXP ValidatorHandler throws an exception if the document is invalid

Added by Michael Kay 12 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
JAXP Java API
Sprint/Milestone:
-
Start date:
2023-04-03
Due date:
% Done:

100%

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

Description

It appears that Saxon's implementation of the JAXP ValidatorHandler interface throws an exception if the document is found to be invalid. The API specification is silent on the point, but it appears this is not the intended behaviour, and it's not the way the Xerces implementation works.

The difference is noted in a comment in the sample application SchemaValidatorHandlerExample, which as far as I can see is our only test case for this API.

Reported by a user on support email. In the use case in question, the ValidatorHandler is being invoked from a JAXP marshaller, and in this situation compatible behaviour with Xerces is essential to make this work.

Actions #1

Updated by Michael Kay 12 months ago

Looking at the specification of XMLReader.parse(), it is just amazingly bad:

Throws: SAXException - Any SAX exception, possibly wrapping another exception. IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.

No indication at all as to whether or not it's expected to throw a SAXException in the event that an invalidity was found.

My immediate concern however is that we don't appear to be calling the supplied ErrorHandler for each validity error.

Actions #2

Updated by Michael Kay 12 months ago

Indeed, although the application calls ValidatorHandler.setErrorHandler(eh), the validity messages are being sent to an InvalidityHandler that wraps the standard ErrorReporter rather than the user-supplied ErrorHandler.

Getting this right is proving troublesome. Schema.newValidatorHandler() constructs a pipeline to perform the full validation, and a subsequent call on setErrorHandler() (or setResourceResolver()) needs to dive deeply into this pipeline to change some of its properties. This is clearly under-tested.

The InvalidityHandler is a property of the ValidationContext object. The simplest solution seems to be to add the ValidationContext as a property of the PipelineConfiguration, allowing ValidationHandler.setErrorHandler() to access it and set its InvalidityHandler.

Actions #3

Updated by Michael Kay 12 months ago

Now returning to the question of parse() throwing an exception at the end. This comes from ValidatingFilter.reportIfInvalid(), which tests the property getPipelineConfiguration().isRecoverFromValidationErrors(). The least disruptive solution seems to be for SchemaReference.newValidatorHandler() to set this property.

Actions #4

Updated by Michael Kay 12 months ago

I have added a set of unit tests for the JAXP ValidatorHandler.

Actions #5

Updated by Michael Kay 12 months ago

  • Status changed from New to Resolved
  • Applies to branch 11, 12, trunk added
  • Fix Committed on Branch 11, 12, trunk added
Actions #6

Updated by O'Neil Delpratt 11 months ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 12.2 added

Bug fix applied in the Saxon 12.2 maintenance release.

Actions #7

Updated by Debbie Lockett 7 months ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 11.6 added

Bug fix applied in the Saxon 11.6 maintenance release.

Please register to edit this issue

Also available in: Atom PDF