Project

Profile

Help

Bug #6145

closed

Saxon 10.6 - NPE in pattern array(XX) when XSLT 4.0 extensions are not enabled

Added by Vladimir Nesterovsky 12 months ago. Updated 12 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2023-07-29
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
10
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

I have typed invalid xslt and got obscure NPE:

     [java] [1]:java.lang.NullPointerException: Cannot invoke "net.sf.saxon.expr.parser.Tokenizer.recentText(int)" because "this.t" is null
     [java] [1] 	at net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:299)
     [java] [1] 	at net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:268)
     [java] [1] 	at net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:255)
     [java] [1] 	at net.sf.saxon.expr.parser.XPathParser.checkSyntaxExtensions(XPathParser.java:3067)
     [java] [1] 	at net.sf.saxon.pattern.PatternParser30.isSelectionPattern(PatternParser30.java:165)
     [java] [1] 	at net.sf.saxon.pattern.PatternParser30.parsePattern(PatternParser30.java:62)
     [java] [1] 	at net.sf.saxon.pattern.Pattern.make(Pattern.java:59)
     [java] [1] 	at net.sf.saxon.style.StyleElement.makePattern(StyleElement.java:723)
     [java] [1] 	at net.sf.saxon.style.XSLTemplate.prepareAttributes(XSLTemplate.java:371)
     [java] [1] 	at net.sf.saxon.style.StyleElement.processAttributes(StyleElement.java:594)
     [java] [1] 	at net.sf.saxon.style.StyleElement.processAllAttributes(StyleElement.java:531)
     [java] [1] 	at net.sf.saxon.style.XSLTemplate.processAllAttributes(XSLTemplate.java:428)
     [java] [1] 	at net.sf.saxon.style.PrincipalStylesheetModule.processAllAttributes(PrincipalStylesheetModule.java:589)
     [java] [1] 	at net.sf.saxon.style.PrincipalStylesheetModule.preprocess(PrincipalStylesheetModule.java:366)
     [java] [1] 	at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:288)
     [java] [1] 	at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:252)
     [java] [1] 	at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:113)
     [java] [1] 	at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:838)
     [java] [1] 	at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:184)

Almost nothing in error report helps to identify the problem. Error is in these lines:

  <xsl:template mode="x" match="array(element())" as="map(*)">
    ...
  </xsl:template>

Match should be: match=".[. instance of array(element())]".

Please note that I did not test it in newer versions.

Actions #1

Updated by Michael Kay 12 months ago

It's trying to tell you that you haven't enabled Saxon syntax extensions, and it crashes because it's accessing unitialised data while constructing the error message.

Actions #2

Updated by Michael Kay 12 months ago

The problem seems to be still present, in modified form, in later releases.

Recommended actions:

(a) make the error-reporting code more resilient (avoids the crash, leaves the message with no location information) (b) delay the checking until the parser is fully initialized (c) improved testing (too much of our testing is done with all optional features enabled)

Actions #3

Updated by Michael Kay 12 months ago

  • Subject changed from NPE in pattern during compilatio in Saxon 10.6 HE to NPE in pattern array(XX) when XSLT 4.0 extensions are not enabled
Actions #4

Updated by Michael Kay 12 months ago

  • Category set to Diagnostics
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
Actions #5

Updated by Michael Kay 12 months ago

It seems that the XSLT test driver, unlike the XQuery/XPath test driver, doesn't allow multiple version strings in the spec version dependency, so a test specifying `<dependency type="spec" value="XSLT20 XSLT30" isn't being run. Many of the tests designed to ensure that 4.0 syntax is rejected when 4.0 isn't available use this formulation.

Actions #6

Updated by Michael Kay 12 months ago

I've fixed the test driver, and the relevant tests in the arrays test-set are now being run, which is revealing quite a few problems (mainly minor, like incorrect error codes). However, the test arrays-010b that was designed to reproduce this problem fails to do so on the 12.x branch.

Actions #7

Updated by Michael Kay 12 months ago

  • Applies to branch 10 added
Actions #8

Updated by Michael Kay 12 months ago

In the 10.x branch, the new test arrays-010b reproduces the failure.

On the 11.x branch, many of the tests that should fail if 4.0 is not enabled actually succeed.

Actions #9

Updated by Michael Kay 12 months ago

Given the variation between releases, for 10.x I've done a minimal ad-hoc patch on the error-handling path.

For 11.x, the problem is that the flag allowXPath40Syntax is set to true. I think this is because the stylesheet says version="4.0". The documentation is clear that this should not be enough to enable 4.0 features. But ExpressionContext.getXPathVersion() has the logic

if (element.getEffectiveVersion() == 40
                || element.getCompilation().getCompilerInfo().getXsltVersion() == 40
                || (attributeName != null && attributeName.hasURI(NamespaceConstant.SAXON))) {
            return 40;

Changing this could be a bit disruptive, but the documentation is clear enough.

When I fix this, tests array-006b and array-020b still fail to report an error. This is because Saxon 11 is allowing new 4.0 functions in the array namespace to be called regardless of version settings.

The tests are all passing on the 12.x branch, but in some cases the error codes differ from those expected.

Actions #10

Updated by Michael Kay 12 months ago

Note that some of the array tests still fail on 10.x, notably arrays-306 fails with a stack overflow because we decided not to fix bug #5600 on the 10.x branch. Although I've pushed a patch for the NPE, it's quite possible that we will not produce any further maintenance releases on the 10.x branch.

Actions #11

Updated by Michael Kay 12 months ago

  • Status changed from New to Resolved
  • Fix Committed on Branch 10 added
  • Platforms .NET, Java added

I've transferred the 11.x problems to a separate issue #6156.

Actions #12

Updated by Michael Kay 12 months ago

  • Subject changed from NPE in pattern array(XX) when XSLT 4.0 extensions are not enabled to Saxon 10.6 - NPE in pattern array(XX) when XSLT 4.0 extensions are not enabled

Please register to edit this issue

Also available in: Atom PDF