Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE with higher order functions #2779

Open
peterstadler opened this issue Jun 3, 2019 · 8 comments
Open

NPE with higher order functions #2779

peterstadler opened this issue Jun 3, 2019 · 8 comments
Assignees
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Milestone

Comments

@peterstadler
Copy link
Contributor

What is the problem

In trying to migrate an eXist app currently running on eXist 3.3 to current 4.7 I hit a strange NPE. The actual code is scattered across several modules and functions but I was able to squeeze it into a single reproducible test (yet, the code does not make much sense anymore ;)

The issue might be related to #2577 and/or #2385?

Describe how to reproduce or add a test

xquery version "3.1";

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

(: first object :)
declare function ct2:obj1($item as item()*) as map(*) {
    map {
        'name' : 'obj1',
        'check' : function() as xs:boolean {
            matches($item, 'foo')
        },
        'test' : function() { ct2:do-something($item) }
    }
};

(: second object, referencing a function from object1 :)
declare function ct2:obj2($item as item()*) as map(*) {
    map {
        'name' : 'obj2',
        'check' : function() as xs:boolean {
            not(ct2:obj1($item)('check')())
        },
        'test' : function() { ct2:do-something($item) }
    }
};

(: some function calling ct2:name-by-id() :)
(: this is only introduced to catch the NPE and make it more readable :)
declare function ct2:do-something($id as xs:string) as xs:string+ {
    try { ct2:name-by-id($id) } catch * { $err:code cast as xs:string }
};

(: iterate over objects and return their name, if the test passes :)
declare function ct2:name-by-id($id as xs:string) as xs:string+ {
    for $func in $ct2:functions
    return 
        if($func($id)('check')()) then $func($id)('name')
        else ()
};

(: expose objects :)
declare variable $ct2:functions := 
    for $func in inspect:module-functions()
    return 
        if(function-name($func) => starts-with('ct2:obj')) then $func
        else ()
;

(: now following the tests … :)
declare 
    %test:assertEquals('obj1') 
    function ct2:test1() as xs:string {
        ct2:obj1('foo')('test')()
    };

declare 
    %test:assertEquals('obj1') 
    function ct2:test2() as xs:string {
        ct2:obj2('foo')('test')()
    };

declare 
    %test:assertEquals('obj1', 'obj1') 
    function ct2:test3() as xs:string+ {
        ct2:obj1('foo')('test')(),
        ct2:obj2('foo')('test')()
    };

Test output

<testsuites>
    <testsuite package="http://exist-db.org/xquery/closures/test2"
        timestamp="2019-06-02T14:29:02.281Z" tests="3" failures="1" errors="0" pending="0"
        time="PT0.011S">
        <testcase name="test1" class="ct2:test1">
            <failure message="assertEquals failed." type="failure-error-code-1">obj1</failure>
            <output>java:java.lang.NullPointerException</output>
        </testcase>
        <testcase name="test2" class="ct2:test2"/>
        <testcase name="test3" class="ct2:test3"/>
    </testsuite>
</testsuites>

NB: the single invocation of ct2:obj1('foo')('test')() fails (= testcase 1) but the combination with a successful call to ct2:obj2('foo')('test')() works (= testcase 3).

Context information

  • eXist Version : 4.7.0
  • eXist Build : 201905201236
  • Git commit : 64ba513
  • Java 1.8.0_212 IcedTea (OpenJDK 64-Bit Server VM)
  • Operating System : Linux 4.9.125-linuxkit amd64
  • running from Docker image stadlerpeter/existdb:4.7
@triage-new-issues triage-new-issues bot added the triage issue needs to be investigated label Jun 3, 2019
@adamretter
Copy link
Member

@peterstadler Do you have the stracktrace for the NPE? It could be in exist.log?

@adamretter adamretter added the bug issue confirmed as bug label Jun 3, 2019
@triage-new-issues triage-new-issues bot removed the triage issue needs to be investigated label Jun 3, 2019
@dizzzz dizzzz added the awaiting-response requires additional information from submitter label Jun 3, 2019
@peterstadler
Copy link
Contributor Author

peterstadler commented Jun 3, 2019

Sorry, in exist.log there's only

2019-06-03 16:03:56,484 [qtp1276894402-47] ERROR (XQueryServlet.java [process]:552) - null 
java.lang.NullPointerException: null

@adamretter
Copy link
Member

@peterstadler okay thanks (I removed your thread-dump as that doesn't help here).

@peterstadler
Copy link
Contributor Author

This still has the "awaiting response" label. Is there anything more I could/should provide?

@wolfgangmm
Copy link
Member

@peterstadler somehow I thought I addressed this issue, but maybe it was a different one. I'll retest.

@peterstadler
Copy link
Contributor Author

Just checked myself with a recent eXist 4.7.1 and the error still occurs.

@line-o line-o added xquery issue is related to xquery implementation and removed awaiting-response requires additional information from submitter labels Apr 8, 2020
@line-o
Copy link
Member

line-o commented Apr 8, 2020

Can be reproduced. exist version 5 is affected.

@adamretter adamretter added this to the eXist-4.7.2 milestone Apr 8, 2020
@peterstadler
Copy link
Contributor Author

ping, ping – any updates here?
Needless to say that I'd really love to see this issue fixed for migrating my app to eXist5 …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Projects
None yet
Development

No branches or pull requests

5 participants