Skip to content

Commit eb58edc

Browse files
committed
fixes an NPE resulting from expression using range index not being properly initialized due to lack of call to resetState after analyzing OrderByClause
1 parent dca4d9a commit eb58edc

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/org/exist/xquery/OrderByClause.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void accept(ExpressionVisitor visitor) {
9999
@Override
100100
public void resetState(boolean postOptimization) {
101101
super.resetState(postOptimization);
102+
returnExpr.resetState(postOptimization);
102103
stack.clear();
103104
}
104105
}

test/src/xquery/xquery3/flwor.xql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,62 @@ module namespace flwor="http://exist-db.org/xquery/test/flwor";
44

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

7+
declare variable $flwor:COLLECTION_CONFIG :=
8+
<collection xmlns="http://exist-db.org/collection-config/1.0">
9+
<index xmlns:xs="http://www.w3.org/2001/XMLSchema">
10+
<fulltext default="none" attributes="false"/>
11+
<range>
12+
<create qname="place">
13+
<field name="place-id" type="xs:string" match="@xml:id"/>
14+
<field name="place-name" type="xs:string" match="placeName"/>
15+
</create>
16+
</range>
17+
</index>
18+
</collection>;
19+
20+
declare variable $flwor:DATA :=
21+
<listPlace>
22+
<place xml:id="warsaw">
23+
<placeName>Warsaw</placeName>
24+
</place>
25+
<place xml:id="berlin">
26+
<placeName>Berlin</placeName>
27+
</place>
28+
</listPlace>;
29+
30+
declare variable $flwor:COLLECTION_NAME := "flwortest";
31+
declare variable $flwor:COLLECTION := "/db/" || $flwor:COLLECTION_NAME;
32+
33+
declare
34+
%test:setUp
35+
function flwor:setup() {
36+
xmldb:create-collection("/db/system/config/db", $flwor:COLLECTION_NAME),
37+
xmldb:store("/db/system/config/db/" || $flwor:COLLECTION_NAME, "collection.xconf", $flwor:COLLECTION_CONFIG),
38+
xmldb:create-collection("/db", $flwor:COLLECTION_NAME),
39+
xmldb:store($flwor:COLLECTION, "test.xml", $flwor:DATA)
40+
};
41+
42+
declare
43+
%test:tearDown
44+
function flwor:cleanup() {
45+
xmldb:remove($flwor:COLLECTION),
46+
xmldb:remove("/db/system/config/db/" || $flwor:COLLECTION_NAME)
47+
};
48+
49+
declare function flwor:test($a) {
50+
collection($flwor:COLLECTION_NAME)//place[placeName = "berlin"]/string()
51+
};
52+
53+
54+
declare
55+
%test:assertEquals("Berlin")
56+
function flwor:order-by-with-range() {
57+
for $i in 1 to 2
58+
order by $i
59+
return
60+
flwor:test("Berlin")
61+
};
62+
763
(: https://github.com/eXist-db/exist/issues/739#issuecomment-130997865 :)
864
declare
965
%test:assertEquals(1, 2, 1, 2, 3, 1, 2, 3, 4)
@@ -78,3 +134,4 @@ function flwor:allowing-empty($n as xs:integer) {
78134
where not($x = 5)
79135
return concat("[", $x, "]")
80136
};
137+

0 commit comments

Comments
 (0)