Skip to content

Commit 0f76cf2

Browse files
line-oadamretter
authored andcommitted
[fix] null contextItem and ~Sequence in functions
- User defined functions do not receive contextItem and contextSequence according to the XQuery 3.1 specification. - The DeferredFunctionCallTest is adapted to reflect that change. - The method `Query#preSelect` in the lucene extension returns an empty set when the contextSequence is null. It would otherwise result in an NPE.
1 parent 35249a7 commit 0f76cf2

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

exist-core/src/main/java/org/exist/xquery/UserDefinedFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
158158
". Expected " + getSignature().getArgumentTypes()[j].getCardinality().getHumanDescription() +
159159
", got " + currentArguments[j].getItemCount());}
160160
}
161-
result = body.eval(contextSequence, contextItem);
161+
result = body.eval(null, null);
162162
return result;
163163
} finally {
164164
// restore the local variable stack

exist-core/src/test/java/org/exist/xquery/DeferredFunctionCallTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void ensure_argumentsToDeferredFunctionCall_AreNotLost_AfterReset_And_Bef
102102
expect(mockContext.declareVariableBinding((LocalVariable)anyObject())).andReturn(null);
103103
expect(mockFunctionSignature.getArgumentTypes()).andReturn(mockArgumentTypes);
104104

105-
expect(mockExpression.eval(mockContextSequence, mockContextItem)).andReturn(Sequence.EMPTY_SEQUENCE);
105+
expect(mockExpression.eval(null, null)).andReturn(Sequence.EMPTY_SEQUENCE);
106106

107107
mockExpression.resetState(true);
108108

extensions/indexes/lucene/src/main/java/org/exist/xquery/modules/lucene/Query.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,17 @@ public int getOptimizeAxis() {
197197
}
198198

199199
public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XPathException {
200-
if (contextSequence != null && !contextSequence.isPersistentSet())
200+
// guard against an empty contextSequence
201+
if (contextSequence == null || !contextSequence.isPersistentSet()) {
201202
// in-memory docs won't have an index
202203
return NodeSet.EMPTY_SET;
203-
204+
}
205+
204206
long start = System.currentTimeMillis();
205207
// the expression can be called multiple times, so we need to clear the previous preselectResult
206208
preselectResult = null;
207209
LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
208210

209-
// DW: contextSequence can be null
210211
DocumentSet docs = contextSequence.getDocumentSet();
211212
Item key = getKey(contextSequence, null);
212213
List<QName> qnames = new ArrayList<>(1);

0 commit comments

Comments
 (0)