https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2020-03-11T08:14:56ZSaxonica Developer CommunitySaxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150362020-03-11T08:14:56ZPranay Deshpande
<ul><li><strong>File</strong> <a href="/attachments/48930">StackTraces.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/48930/StackTraces.txt">StackTraces.txt</a> added</li></ul> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150372020-03-11T08:53:20ZMichael Kaymike@saxonica.com
<ul></ul><p>Thanks for reporting it. I have reproduced the error under 9.9 1.7.</p>
<p>I've also established that it goes away if you disable optimization, so for a quick workaround, you can switch optimization off: use -opt:0 on the command line, or set the configuration property OPTIMIZATION_LEVEL to the value "0".</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150382020-03-11T09:11:55ZMichael Kaymike@saxonica.com
<ul><li><strong>Category</strong> set to <i>Internals</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>In Progress</i></li><li><strong>Assignee</strong> set to <i>Michael Kay</i></li><li><strong>Priority</strong> changed from <i>High</i> to <i>Normal</i></li><li><strong>Applies to branch</strong> <i>9.9, trunk</i> added</li></ul><p>The problem is with the variable <code>$altova:nodeTable</code> on line 1231.</p>
<p>The function <code>altova:GetGridRowNumForCell</code> has been inlined at the point of the call from <code>altova:col-position()</code> on line 1077. Running with function inlining suppressed (<code>-opt:-f</code>) makes the problem go away. The regression from earlier releases is probably because (after conducting experiments) we changed the threshold for the size of functions that are eligible for inlining.</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150392020-03-11T09:20:29ZPranay Deshpande
<ul></ul><p>Hi Michael,</p>
<p>Thanks for providing the quick workaround.</p>
<p>I wanted to know is there something we can change in the XSLT file and resolve this issue temporarily?</p>
<p>Also, could you please confirm, once the issue is fixed from your end, could you downport it to 9.9.1.6 version?</p>
<p>Regards
Pranay</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150402020-03-11T09:31:30ZMichael Kaymike@saxonica.com
<ul></ul><p>There's no direct way to switch optimizations off from within the XSLT file itself, it has to be done from the calling application or shell script.</p>
<p>However, it's possible to rewrite the function in such a way that it doesn't get inlined. The simplest way is probably to make the function recursive: in the xsl:choose at line 1233, add a never-executed branch</p>
<pre><code> <xsl:when test="$altova:sTableSection eq 'something-impossible'">
<xsl:sequence select="altova:GetGridRowNumForCell($altova:nodeTableCell)"/>
</xsl:when>
</code></pre>
<p>I tried that and it seems to work.</p>
<p>The eventual fix will be in a new maintenance release, likely to be numbered 9.9.1.8.</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150412020-03-11T09:56:04ZMichael Kaymike@saxonica.com
<ul></ul><p>The -explain output shows:</p>
<pre><code>At line 1077 of file:/Users/mike/bugs/2020/4478-Deshpande/problem.xsl
OPT : Moved function altova:GetGridRowNumForCell inline:
OPT : Expression after rewrite:
let $Q{http://www.altova.com}nodeTableCell := $Q{http://www.altova.com}Cell
return (bytecode(
let $Q{http://www.altova.com}nodeTableRow := exactly-one($Q{http://www.altova.com}nodeTableCell/parent::(document-node()|element()))
return (
let $Q{http://www.altova.com}nodeTableSection := exactly-one($Q{http://www.altova.com}nodeTableRow/parent::(document-node()|element()))
return (
let $Q{http://www.altova.com}nodeTable := exactly-one($Q{http://www.altova.com}nodeTableSection/parent::(document-node()|element())) return (let $Q{http://www.altova.com}nRowNumInSection := (count($Q{http://www.altova.com}nodeTableRow/preceding-sibling::element(Q{}tr))) + 1
return (SwitchExpression(local-name($Q{http://www.altova.com}nodeTableSection)....)
</code></pre>
<p>At this stage things look OK.</p>
<p>But we then see:</p>
<pre><code>Eliminated unused variable altova:nodeTable
OPT : Expression after rewrite: SwitchExpression(local-name($Q{http://www.altova.com}nodeTableSection), ....
</code></pre>
<p>and this is clearly wrong, because the variable is not unused; we are left with references to a variable that has no binding.</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150422020-03-11T11:45:36ZMichael Kaymike@saxonica.com
<ul></ul><p>At some point in the optimization process the <code>LetExpression</code> binding <code>$altova:nodeTable</code> at @8515 has been replaced by a new <code>LetExpression</code> @11184, but the variable references in its action part have not been rebound to the new <code>LetExpression</code>.</p>
<p>This is happening when the expression is copied during function inlining.</p>
<p>The code for <code>SwitchExpression.copy()</code> is not performing a deep copy of its operands, so the variable references retain their old bindings. (A <code>SwitchExpression</code> is the optimized form of an <code>xsl:choose</code> where all the branches are equality tests on the same subexpression).</p>
<p>Fixed by changing <code>SwitchExpression</code> to deep-copy the action operands.</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150432020-03-11T11:48:00ZMichael Kaymike@saxonica.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Resolved</i></li><li><strong>Fix Committed on Branch</strong> <i>9.9, trunk</i> added</li></ul> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=150702020-03-17T12:48:20ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Fixed in Maintenance Release</strong> <i>10.0</i> added</li></ul><p>Bug fix applied in the Saxon 10 major release.</p> Saxon - Bug #4478: java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.om.Sequence.head() of a null object loaded from local variable 'actual'https://saxonica.plan.io/issues/4478?journal_id=165932020-10-22T16:16:07ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li><li><strong>Fixed in Maintenance Release</strong> <i>9.9.1.8</i> added</li></ul><p>Bug fix applied on the Saxon 9.9.1.8 maintenance release.</p>