Skip to content

Commit e01fe74

Browse files
committed
[bugfix] Correct NPE check so that NodeSet sizing hint is used
1 parent 51b17a7 commit e01fe74

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@
811811
<exclude>src/main/java/org/exist/dom/memtree/NamespaceNode.java</exclude>
812812
<include>src/main/java/org/exist/dom/memtree/NodeImpl.java</include>
813813
<exclude>src/main/java/org/exist/dom/memtree/ProcessingInstructionImpl.java</exclude>
814+
<include>src/main/java/org/exist/dom/persistent/AbstractArrayNodeSet.java</include>
814815
<include>src/main/java/org/exist/dom/persistent/AbstractCharacterData.java</include>
815816
<include>src/main/java/org/exist/dom/persistent/AttrImpl.java</include>
816817
<include>src/main/java/org/exist/dom/persistent/BinaryDocument.java</include>
@@ -823,6 +824,7 @@
823824
<include>src/main/java/org/exist/dom/persistent/Match.java</include>
824825
<include>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</include>
825826
<include>src/main/java/org/exist/dom/persistent/NodeProxy.java</include>
827+
<include>src/main/java/org/exist/dom/persistent/NodeSet.java</include>
826828
<include>src/test/java/org/exist/dom/persistent/NodeTest.java</include>
827829
<include>src/main/java/org/exist/dom/persistent/LockToken.java</include>
828830
<include>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</include>
@@ -1245,6 +1247,7 @@
12451247
<exclude>src/main/java/org/exist/dom/memtree/reference/ElementReferenceImpl.java</exclude>
12461248
<exclude>src/main/java/org/exist/dom/memtree/reference/ProcessingInstructionReferenceImpl.java</exclude>
12471249
<exclude>src/main/java/org/exist/dom/memtree/reference/TextReferenceImpl.java</exclude>
1250+
<exclude>src/main/java/org/exist/dom/persistent/AbstractArrayNodeSet.java</exclude>
12481251
<exclude>src/main/java/org/exist/dom/persistent/AbstractCharacterData.java</exclude>
12491252
<exclude>src/main/java/org/exist/dom/persistent/AttrImpl.java</exclude>
12501253
<exclude>src/main/java/org/exist/dom/persistent/BinaryDocument.java</exclude>
@@ -1257,6 +1260,7 @@
12571260
<exclude>src/main/java/org/exist/dom/persistent/Match.java</exclude>
12581261
<exclude>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</exclude>
12591262
<exclude>src/main/java/org/exist/dom/persistent/NodeProxy.java</exclude>
1263+
<exclude>src/main/java/org/exist/dom/persistent/NodeSet.java</exclude>
12601264
<exclude>src/test/java/org/exist/dom/persistent/NodeTest.java</exclude>
12611265
<exclude>src/main/java/org/exist/dom/persistent/LockToken.java</exclude>
12621266
<exclude>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</exclude>

exist-core/src/main/java/org/exist/dom/persistent/AbstractArrayNodeSet.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*

exist-core/src/main/java/org/exist/dom/persistent/AbstractNodeSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public NodeSet getContextNodes(final int contextId) {
547547
if (Expression.NO_CONTEXT_ID != contextId) {
548548
context.addContextNode(contextId, context);
549549
}
550-
if (lastDoc != null && lastDoc.getDocId() != context.getOwnerDocument().getDocId()) {
550+
if (lastDoc == null || lastDoc.getDocId() != context.getOwnerDocument().getDocId()) {
551551
lastDoc = context.getOwnerDocument();
552552
result.add(context, getSizeHint(lastDoc));
553553
} else {

exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,10 @@ public NodeSet getContextNodes(final int contextId) {
964964
if(contextNode.getContextId() == contextId) {
965965
final NodeProxy context = contextNode.getNode();
966966
context.addMatches(current);
967-
if(Expression.NO_CONTEXT_ID != contextId) {
967+
if (Expression.NO_CONTEXT_ID != contextId) {
968968
context.addContextNode(contextId, context);
969969
}
970-
if(lastDoc != null && lastDoc.getDocId() != context.getOwnerDocument().getDocId()) {
970+
if (lastDoc == null || lastDoc.getDocId() != context.getOwnerDocument().getDocId()) {
971971
lastDoc = context.getOwnerDocument();
972972
result.add(context, getSizeHint(lastDoc));
973973
} else {

exist-core/src/main/java/org/exist/dom/persistent/NodeSet.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -377,7 +401,7 @@ boolean matchAncestorDescendant(NodeSet al, int mode, boolean includeSelf,
377401
*
378402
* @param contextId used to track context nodes when evaluating predicate
379403
* expressions. If contextId != {@link org.exist.xquery.Expression#NO_CONTEXT_ID}, the current context
380-
* will be added to each result of the of the selection.
404+
* will be added to each result of the selection.
381405
* @return all context nodes associated with the nodes in this node set.
382406
*/
383407
NodeSet getContextNodes(int contextId);

0 commit comments

Comments
 (0)