{"action":"opened","issue":{"url":"https://api.github.com/repos/eXist-db/exist/issues/2099","repository_url":"https://api.github.com/repos/eXist-db/exist","labels_url":"https://api.github.com/repos/eXist-db/exist/issues/2099/labels{/name}","comments_url":"https://api.github.com/repos/eXist-db/exist/issues/2099/comments","events_url":"https://api.github.com/repos/eXist-db/exist/issues/2099/events","html_url":"https://github.com/eXist-db/exist/issues/2099","id":347442796,"node_id":"MDU6SXNzdWUzNDc0NDI3OTY=","number":2099,"title":"NullPointer for nesting for with group and order","user":{"login":"ahenket","id":5390573,"node_id":"MDQ6VXNlcjUzOTA1NzM=","avatar_url":"https://avatars2.githubusercontent.com/u/5390573?v=4","gravatar_id":"","url":"https://api.github.com/users/ahenket","html_url":"https://github.com/ahenket","followers_url":"https://api.github.com/users/ahenket/followers","following_url":"https://api.github.com/users/ahenket/following{/other_user}","gists_url":"https://api.github.com/users/ahenket/gists{/gist_id}","starred_url":"https://api.github.com/users/ahenket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahenket/subscriptions","organizations_url":"https://api.github.com/users/ahenket/orgs","repos_url":"https://api.github.com/users/ahenket/repos","events_url":"https://api.github.com/users/ahenket/events{/privacy}","received_events_url":"https://api.github.com/users/ahenket/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-03T15:33:53Z","updated_at":"2018-08-03T15:33:53Z","closed_at":null,"author_association":"NONE","body":"eXist-db 4.3.1 macOS Mojave.\r\n\r\nI'm trying to get to the core of the problem but so far I cannot get closer than this query fragment:\r\n\r\n```\r\ndeclare variable $colDecorCache     := collection('/db/apps/decor/cache');\r\ndeclare variable $colDecorData      := collection('/db/apps/decor/data');\r\n\r\ndeclare function local:getTemplateById($id as xs:string, $flexibility as xs:string?, $prefix as xs:string, $version as xs:string?) {\r\n\r\nlet $internalrepositories       := $colDecorData/decor[project/@prefix = $prefix][1]\r\nlet $buildingBlockRepositories  := $internalrepositories/project/buildingBlockRepository\r\nlet $x                          := local:getTemplateById($prefix, $id, $prefix, $buildingBlockRepositories, ())\r\n\r\nreturn ()\r\n};\r\n\r\ndeclare %private function local:getTemplateById($basePrefix as xs:string, $id as xs:string, $prefix as xs:string, $externalrepositorylist as element()*, $bbrList as element()*) as element()* {\r\n    for $repository in $externalrepositorylist\r\n    let $repourl                := $repository/@url\r\n    let $repoident              := $repository/@ident\r\n    return\r\n        <repositoryTemplateList>\r\n        {\r\n                let $cachedProject  := $colDecorCache//cacheme[@bbrident = $repoident][@bbrurl = $repourl]/decor\r\n                return ()\r\n        }\r\n        </repositoryTemplateList>\r\n};\r\n\r\n<x>\r\n{\r\n    (: Don't show links for templates in versioned projects :)\r\n    for $projectTemplateSet in $colDecorData/decor[@repository = 'true']//template[@ref]\r\n    let $prefix                 := $projectTemplateSet/ancestor::decor/project/@prefix\r\n    let $tid                    := $projectTemplateSet/@id | $projectTemplateSet/@ref\r\n    group by $prefix, $tid\r\n    order by $prefix, $tid\r\n    return (\r\n        for $template in $projectTemplateSet\r\n        return (\r\n            if ($template[@ref]) then (\r\n                local:getTemplateById($template/@ref, 'dynamic', $prefix, ())//template[@id]\r\n            ) else ()\r\n        )\r\n    )\r\n}\r\n</x>\r\n```\r\n\r\nThis code yields a NullPointException from the exist.log no stack trace:\r\n\r\n```\r\n2018-08-03 17:30:41,336 [qtp1226557879-3531] INFO  (XQueryServlet.java [init]:158) - encoding = UTF-8 \r\n2018-08-03 17:30:41,371 [qtp1226557879-3531] ERROR (XQueryServlet.java [process]:552) - null \r\njava.lang.NullPointerException: null\r\n```\r\n\r\nWhen I remove the line \"order by $prefix, $tid\" the xquery finishes normally. When I remove the line \"let $cachedProject  := $colDecorCache//cacheme[@bbrident = $repoident][@bbrurl = $repourl]/decor\" the xquery finishes normally.\r\n\r\nThe collection that $colDecorCache operates on has combined range indexes configured.\r\n\r\nThis xquery fragment is hard to replay anywhere else because of data requirements. I still hope we can get to the bottom of it.\r\n"}}
{"actor":{"display_login":"ahenket"}}