Skip to content

Commit a3d451c

Browse files
committed
OAK-11607 the ordered children property can be null; make the test more robust
1 parent 4eedc30 commit a3d451c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/OrderedChildnameIterable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.apache.jackrabbit.oak.plugins.tree.impl;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
45
import java.util.HashSet;
56
import java.util.Iterator;
67
import java.util.List;
@@ -41,7 +42,7 @@ public class OrderedChildnameIterator implements Iterator<String> {
4142
private Iterator<String> nonOrderedChildrenIterator = null;
4243

4344
public OrderedChildnameIterator (Iterable<String> orderedChildren, Iterable<String> allChildren) {
44-
this.orderedChildren = orderedChildren.iterator();
45+
this.orderedChildren = orderedChildren == null ? Collections.emptyIterator() : orderedChildren.iterator();
4546
this.allChildren = allChildren.iterator();
4647
nextResult = getNextElement();
4748
}

oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/ChildOrderPropertyTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertNull;
2222
import static org.junit.Assert.assertTrue;
2323

24+
import java.util.ArrayList;
2425
import java.util.List;
2526
import java.util.Set;
2627

@@ -32,6 +33,7 @@
3233
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
3334
import org.apache.jackrabbit.oak.plugins.tree.TreeConstants;
3435
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
36+
import org.junit.Assert;
3537
import org.junit.Before;
3638
import org.junit.Test;
3739

@@ -98,7 +100,11 @@ public void testChildOrderWithoutPropertyReadAccess() throws Exception {
98100
assertFalse(aTree.hasProperty(JcrConstants.JCR_PRIMARYTYPE));
99101

100102
List<String> expected = List.of("/a/bb", "/a/b");
101-
Iterable<String> childPaths = IterableUtils.transform(aTree.getChildren(), input -> input.getPath());
102-
assertTrue(childPaths.toString(), IterableUtils.elementsEqual(expected, childPaths));
103+
104+
// Collect actual paths into a list
105+
List<String> actual = new ArrayList<>();
106+
aTree.getChildren().forEach( c -> actual.add(c.getPath()));
107+
108+
assertEquals("Child order should be maintained", expected, actual);
103109
}
104110
}

0 commit comments

Comments
 (0)