phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
110 stars 36 forks source link

Exception while creating schematron resource from PEPPOL and CEN #147

Closed nstdio closed 1 year ago

nstdio commented 1 year ago

I'm using com.helger.schematron:ph-schematron-schxslt:7.1.0 to process CEN-EN16931-UBL.sch and PEPPOL-EN16931-UBL.sch files.

When loading CEN-EN16931-UBL.sch I get following error:

java.lang.NullPointerException: Cannot read field "dependees" because "parentInfo" is null
    at net.sf.saxon.expr.parser.LoopLifter.markDependencies(LoopLifter.java:221)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:171)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:174)
    at net.sf.saxon.expr.parser.LoopLifter.gatherInfo(LoopLifter.java:153)
    at net.sf.saxon.expr.parser.LoopLifter.process(LoopLifter.java:53)
    at net.sf.saxon.expr.parser.ExpressionTool.optimizeComponentBody(ExpressionTool.java:978)
    at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:1043)
    at net.sf.saxon.style.PrincipalStylesheetModule.optimizeTopLevel(PrincipalStylesheetModule.java:1496)
    at net.sf.saxon.style.PrincipalStylesheetModule.compile(PrincipalStylesheetModule.java:1315)
    at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:324)
    at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:246)
    at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:113)
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:969)
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:155)
    at com.helger.xml.transform.XMLTransformerFactory.newTemplates(XMLTransformerFactory.java:303)
    at com.helger.schematron.schxslt.xslt2.SchematronProviderXSLTFromSchXslt_XSLT2.<init>(SchematronProviderXSLTFromSchXslt_XSLT2.java:277)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2Cache.createSchematronXSLTProvider(SchematronResourceSchXslt_XSLT2Cache.java:70)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2Cache.getSchematronXSLTProvider(SchematronResourceSchXslt_XSLT2Cache.java:128)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2.getXSLTProvider(SchematronResourceSchXslt_XSLT2.java:138)
    at com.helger.schematron.api.xslt.AbstractSchematronXSLTBasedResource.isValidSchematron(AbstractSchematronXSLTBasedResource.java:197)

However when loading PEPPOL-EN16931-UBL.sch no exception is thrown (actually stacktrace is logged) but ISchematronResource#isValidSchematron returns false.

I'm sure you can easily reproduce these cases in tests for ph-schematron-schxslt.

nstdio commented 1 year ago

Interesting that with 7.0.1 the CEN-EN16931-UBL.sch is parsed just fine.

phax commented 1 year ago

Please stick with ph-schematron 7.0.1 because it uses Saxon HE 11.x. The updated ph-schematron 7.1.0 uses Saxon HE 12.x which seems to have some backwards compatibility issues - I don't know if by accident or by purpose....

nstdio commented 1 year ago

Absolutely. Will use 7.0.1 for now, but PEPPOL-EN16931-UBL.sch does not work with 7.0.1 :disappointed:

phax commented 1 year ago

I don't believe that, as I am using ph-schematron myself with the Peppol rules in the latest phive-rules release. Can you please elaborate on what "does not work" mean exactly?

nstdio commented 1 year ago

I checked out the repository and this stacktrace is from running test on the Peppol in the ph-schematron-schxslt:

3467 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3472 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3474 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3478 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3479 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3480 [main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Cannot find a 1-argument function named Q{utils}TinVerification())
3558 [main] ERROR com.helger.xml.transform.XMLTransformerFactory - Failed to parse javax.xml.transform.dom.DOMSource@514de325
javax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:158)
    at com.helger.xml.transform.XMLTransformerFactory.newTemplates(XMLTransformerFactory.java:303)
    at com.helger.schematron.schxslt.xslt2.SchematronProviderXSLTFromSchXslt_XSLT2.<init>(SchematronProviderXSLTFromSchXslt_XSLT2.java:277)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2Cache.createSchematronXSLTProvider(SchematronResourceSchXslt_XSLT2Cache.java:70)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2Cache.getSchematronXSLTProvider(SchematronResourceSchXslt_XSLT2Cache.java:128)
    at com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2.getXSLTProvider(SchematronResourceSchXslt_XSLT2.java:138)
    at com.helger.schematron.api.xslt.AbstractSchematronXSLTBasedResource.applySchematronValidation(AbstractSchematronXSLTBasedResource.java:222)
    at com.helger.schematron.api.xslt.AbstractSchematronXSLTBasedResource.applySchematronValidationToSVRL(AbstractSchematronXSLTBasedResource.java:285)
    at com.helger.schematron.AbstractSchematronResource.applySchematronValidationToSVRL(AbstractSchematronResource.java:272)
    at com.helger.schematron.supplementary.Issue137SchXsltTest.validateAndProduceSVRL(Issue137SchXsltTest.java:51)
    at com.helger.schematron.supplementary.Issue137SchXsltTest.testPeppol(Issue137SchXsltTest.java:67)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:976)
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:155)
    ... 35 more
Caused by: net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation
    at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:256)
    at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:113)
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:971)
    ... 36 more
phax commented 1 year ago

Ah - don't use schxslt for the Peppol Schematrons - stick with ISO Schematron please.

nstdio commented 1 year ago

Indeed! Thanks for support and quick responses @phax !

phax commented 1 year ago

yw @nstdio - feel free to use https://github.com/phax/phive and https://github.com/phax/phive-rules directly - it supports not just Peppol but other eInvoicing formats as well :)