Project

Profile

Help

Bug #2590

closed

NPE when saxon:assign refers to an undeclared variable

Added by Radu Coravu almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Saxon extensions
Sprint/Milestone:
Start date:
2016-01-19
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.6, 9.7
Fix Committed on Branch:
9.6, 9.7
Fixed in Maintenance Release:
Platforms:

Description

I obtained a NPE trying to compile a larger XSL.

I reduced the XSL it to this:

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:saxon="http://saxon.sf.net/"
    extension-element-prefixes="saxon">
    
    <xsl:template name="formatStringByToken" as="text()*">
        <xsl:value-of select="$newLine"/>
        <saxon:assign name="remain" select="$prmLength"/>
    </xsl:template>
</xsl:stylesheet>

When I compile it I obtain:

<pre>
java.lang.NullPointerException
	at com.saxonica.xsltextn.style.SaxonAssign.validate(SaxonAssign.java:53)
	at net.sf.saxon.style.StyleElement.validateSubtree(StyleElement.java:1610)
	at net.sf.saxon.style.StyleElement.validateChildren(StyleElement.java:1645)
	at net.sf.saxon.style.StyleElement.validateSubtree(StyleElement.java:1614)
	at net.sf.saxon.style.StylesheetPackage.preprocess(StylesheetPackage.java:478)
	at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:180)
	at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:94)
	at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:543)
	at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:175)
	at net.sf.saxon.jaxp.SaxonTransformerFactory.newTransformer(SaxonTransformerFactory.java:129)
	at ro.sync.xml.transformer.TransformerCreator.createXSLTransformer(TransformerCreator.java:1453)
	at ro.sync.xml.transformer.TransformerCreator.createTransformer(TransformerCreator.java:736)
	at ro.sync.xml.transformer.TransformerCreator.createValidationOnlyTransformer(TransformerCreator.java:597)
	at ro.sync.exml.validate.scanners.StylesheetErrorScanner.scanInternal(StylesheetErrorScanner.java:370)
	at ro.sync.exml.validate.AbstractErrorScanner$1.run(AbstractErrorScanner.java:177)
	at ro.sync.exml.validate.AbstractErrorScanner$1.run(AbstractErrorScanner.java:1)
	at java.security.AccessController.doPrivileged(Native Method)
	at ro.sync.util.security.Sandbox.runWithPerms(Sandbox.java:726)
	at ro.sync.exml.validate.AbstractErrorScanner$2$1$1.run(AbstractErrorScanner.java:211)
	at ro.sync.exml.validate.AbstractErrorScanner$2$1$1.run(AbstractErrorScanner.java:1)
	at ro.sync.util.security.Sandbox.runWithThreadConfirmation(Sandbox.java:921)
	at ro.sync.exml.validate.AbstractErrorScanner$2$1.run(AbstractErrorScanner.java:207)
	at ro.sync.exml.validate.AbstractErrorScanner$2$1.run(AbstractErrorScanner.java:1)
	at ro.sync.util.security.Sandbox.runWithWriteConfirmation(Sandbox.java:898)
	at ro.sync.exml.validate.AbstractErrorScanner$2.run(AbstractErrorScanner.java:203)
	at ro.sync.exml.validate.AbstractErrorScanner$2.run(AbstractErrorScanner.java:1)
	at ro.sync.util.security.Sandbox.runWithConnectConfirmation(Sandbox.java:877)
	at ro.sync.exml.validate.AbstractErrorScanner.scan(AbstractErrorScanner.java:200)
	at ro.sync.exml.validate.scanners.SynchronizedErrorScanner.scan(SynchronizedErrorScanner.java:123)
	at ro.sync.exml.editor.validate.ValidationAssistant.processErrors(ValidationAssistant.java:1244)
	at ro.sync.exml.editor.validate.ValidationAssistant.runValidation(ValidationAssistant.java:890)
	at ro.sync.exml.editor.validate.ValidationAssistant.runValidation(ValidationAssistant.java:763)
	at ro.sync.exml.editor.validate.ValidationAssistant.checkForErrors(ValidationAssistant.java:743)
	at ro.sync.exml.editor.validate.ValidationAssistant$2.appRun(ValidationAssistant.java:637)
	at ro.sync.ui.application.ApplicationThread.run(ApplicationThread.java:133)

Actions #1

Updated by Michael Kay almost 9 years ago

  • Subject changed from NPE obtained with Saxon 9.6.0.6 EE to NPE when saxon:assign refers to an undeclared variable
  • Category set to Saxon extensions
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch 9.7 added

In fact it can be reproduced with the even simpler:

<xsl:template name="formatStringByToken" as="text()*">

<saxon:assign name="remain" select="2"/>

</xsl:template>

where $remain is undeclared.

Actions #2

Updated by Michael Kay almost 9 years ago

  • Status changed from New to Resolved
  • Fix Committed on Branch 9.6, 9.7 added

Patch committed on the 9.6 and 9.7 branches.

The NPE occurred while trying to construct the error message saying the variable was undeclared.

Actions #3

Updated by Radu Coravu almost 9 years ago

Thanks Michael, I stumbled over it when trying to (unsuccessfully) reduce out client's stylesheets which trigger another exception when compiled with optimizations enabled:

java.lang.IllegalArgumentException: Invalid replacement
	at net.sf.saxon.expr.Expression.replaceOperand(Expression.java:1010)
	at net.sf.saxon.expr.parser.ExpressionTool.inlineVariableReferences(ExpressionTool.java:1300)
	at net.sf.saxon.expr.parser.ExpressionTool.inlineVariableReferences(ExpressionTool.java:1303)
	at net.sf.saxon.expr.Assignation.replaceVariable(Assignation.java:470)
	at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:231)
	at net.sf.saxon.expr.parser.ExpressionVisitor.optimize(ExpressionVisitor.java:244)
	at net.sf.saxon.expr.instruct.Block.optimize(Block.java:582)
	at net.sf.saxon.expr.parser.ExpressionVisitor.optimize(ExpressionVisitor.java:244)
	at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:611)
	at net.sf.saxon.style.StylesheetPackage.optimizeTopLevel(StylesheetPackage.java:1256)
	at net.sf.saxon.style.StylesheetPackage.compile(StylesheetPackage.java:1123)
	at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:201)
	at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:94)
	at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:543)
	at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:175)
	at net.sf.saxon.jaxp.SaxonTransformerFactory.newTransformer(SaxonTransformerFactory.java:129)

but we'll try to convince our client to add an issue and provide you with all the stylesheets. By the way, in such cases when applying the optimizations results in errors, maybe you could fall back and avoid any optimization.

Actions #4

Updated by O'Neil Delpratt almost 9 years ago

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

Bug fix applied in the Saxon 9.7.0.2 maintenance release

Actions #5

Updated by O'Neil Delpratt almost 9 years ago

  • Fixed in Maintenance Release 9.7.0.3 added
  • Fixed in Maintenance Release deleted (9.7.0.2)

Bug fix applied in the 9.7.0.3 maintenance release. Leave open until fix applied in the 9.6 branch

Actions #6

Updated by O'Neil Delpratt over 8 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.6.0.9 added
  • Fixed in Maintenance Release deleted (9.7.0.3)

Bug fix applied in the Saxon 9.6.0.9 maintenance release.

Actions #7

Updated by O'Neil Delpratt over 8 years ago

  • Fixed in Maintenance Release 9.7.0.3 added
Actions #8

Updated by O'Neil Delpratt over 8 years ago

  • Sprint/Milestone set to 9.7.0.3

Please register to edit this issue

Also available in: Atom PDF