eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
429 stars 179 forks source link

XQSuite test failure on an XQuery function calling another from a declared variable #1881

Open ptrckb opened 6 years ago

ptrckb commented 6 years ago

What is the problem

An error java:java.lang.NullPointerException is reported in the XQSuite output when the function tested makes a dynamic call to a function in a variable.

There is no additional information in exist.log.

What did you expect

The test should pass with no error.

If executed outsite the test suite, the function does run fine.

Describe how to reproduce or add a test

Testing the following module ('/db/apps/xx.xqm'):

xquery version "3.1";

module namespace xx="http://example.com/xx";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $xx:function := function () {
    ()
};

declare
    %test:assertEmpty
function xx:test1() {
    $xx:function()
};

declare
    %test:assertEmpty
function xx:test2() {
    function () { () }()
};

with the following XQSuite test suite:

xquery version "3.1";

import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace inspect="http://exist-db.org/xquery/inspection";

test:suite( 
    inspect:module-functions(xs:anyURI('xmldb:exist:///db/apps/xx.xqm'))
)

results in this report:

<testsuites>
    <testsuite package="http://example.com/xx" timestamp="2018-05-24T14:27:48.883+02:00" failures="0" pending="0" tests="2" time="PT0.002S">
        <testcase name="test1" class="xx:test1">
            <error type="java:java.lang.NullPointerException" message=""/>
        </testcase>
        <testcase name="test2" class="xx:test2"/>
    </testsuite>
</testsuites>

Context information

Please always add the following information

dizzzz commented 6 years ago

I had similar issues. According to @adamretter this should be fixed in v4.1.1 / v4.2.0 (what ever comes first)

adamretter commented 6 years ago

@dizzzz Nope this is a different one.

A quick Java debug session shows that the problem is somehow with:

declare variable $xx:function := function () {
    ()
};

When InlineFunction#eval(Sequence, Item) is called, it expects that InlineFunction#analyze(AnalyzeContextInfo) was called beforehand. However that is not happening and so a NullPointerException is thrown via line 82 of InlineFunction.java, where an attempt is made to operate on cachedContextInfo which should have been set in analyze but never was (in this instance).

I have no idea how the intended operation should work. I think this is one for @wolfgangmm as he implemented this. Should be a quick fix if one understand why it works in the way it does currently.

duncdrum commented 5 years ago

@wolfgangmm a live sign please