Schematron Peppol validation

375 Views Asked by At

I'm using 'com.helger.schematron:ph-schematron-pure:7.1.0' and I'm trying to valid my peppol xml agains the schematron file 'CEN-EN16931-UBL.sch'

Here my code to valid and outpout the errors:

        final var res = SchematronResourcePure.fromFile(new File("CEN-EN16931-UBL.sch"));
        //if (!res.isValidSchematron())
        //    throw new IllegalArgumentException("Invalid Schematron!");
        res.setErrorHandler(new IPSErrorHandler() {
            @Override
            public void handleError(@Nonnull final IError aError) {

                System.out.println(aError.toString());
            }
        });            
        final SchematronOutputType schematronOutputType = res.applySchematronValidationToSVRL(new StreamSource(new StringReader(xml)));
        SVRLHelper.getAllFailedAssertions(schematronOutputType);

But I get an NullPointerException. Any idea from where this "null" is coming ?

15:17:00.219 [main] DEBUG com.helger.commons.lang.ServiceLoaderHelper - Finished retrieving all 1 SPI implementations of interface com.helger.commons.hashcode.IHashCodeImplementationRegistrarSPI
15:17:00.235 [main] DEBUG com.helger.commons.hashcode.HashCodeImplementationRegistry - Reinitialized com.helger.commons.hashcode.HashCodeImplementationRegistry
15:17:00.793 [main] DEBUG com.helger.schematron.pure.preprocess.PSPreprocessor - Schematron does not need any preprocessing. Returning Schema as-is.
15:17:00.805 [main] DEBUG com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema - Binding pure Schematron
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "net.sf.saxon.value.AtomicValue.equals(Object)" because "a" is null
    at net.sf.saxon.expr.sort.GenericAtomicComparer.lambda$makeAtomicComparisonFunction$6(GenericAtomicComparer.java:248)
    at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForBoolean$4(ValueComparison.java:620)
    at net.sf.saxon.expr.FilterExpression$FilterExprElaborator$SimpleFilteredIterator.next(FilterExpression.java:1391)
    at net.sf.saxon.om.SequenceTool.supply(SequenceTool.java:145)
    at net.sf.saxon.expr.sort.DocumentOrderIterator.<init>(DocumentOrderIterator.java:41)
    at net.sf.saxon.expr.sort.DocumentSorter$DocumentSorterElaborator.lambda$elaborateForPull$0(DocumentSorter.java:331)
    at net.sf.saxon.functions.Count$CountFnElaborator.lambda$elaborateForItem$0(Count.java:135)
    at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForBoolean$4(ValueComparison.java:620)
    at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:181)
    at com.helger.schematron.pure.xpath.XPathEvaluationHelper.evaluate(XPathEvaluationHelper.java:63)
    at com.helger.schematron.pure.xpath.XPathEvaluationHelper.evaluateAsBoolean(XPathEvaluationHelper.java:70)
    at com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema._validateSerial(PSXPathBoundSchema.java:739)
    at com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema.validate(PSXPathBoundSchema.java:807)
    at com.helger.schematron.pure.bound.AbstractPSBoundSchema.validateComplete(AbstractPSBoundSchema.java:259)
    at com.helger.schematron.pure.SchematronResourcePure.applySchematronValidationToSVRL(SchematronResourcePure.java:394)
    at com.helger.schematron.AbstractSchematronResource.applySchematronValidationToSVRL(AbstractSchematronResource.java:286)
1

There are 1 best solutions below

0
Michael Kay On

A NullPointerException deep in Saxon code is prima facie a bug: even if the caller did something wrong, we should have detected it earlier and produced better diagnostics.

The most likely explanation for an NPE at this place in the code is that some expression evaluated to an empty sequence, and Saxon didn't check for this because its static analysis suggested that an empty result wasn't possible at that point.

Happy to look at it if you can construct a repro and submit it at saxonica.plan.io.