Bug #5953
closed
JAXP ValidatorHandler throws an exception if the document is invalid
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
11, 12, trunk
Fixed in Maintenance Release:
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.
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.
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
.
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.
I have added a set of unit tests for the JAXP ValidatorHandler.
- Status changed from New to Resolved
- Applies to branch 11, 12, trunk added
- Fix Committed on Branch 11, 12, trunk added
- % Done changed from 0 to 100
- Fixed in Maintenance Release 12.2 added
Bug fix applied in the Saxon 12.2 maintenance release.
- 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