diff --git a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java index 3b0415a93c1..f371b847d67 100644 --- a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java +++ b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java @@ -192,7 +192,10 @@ private Iterable getChildNodeEntries(NodeState node, S List entries = new ArrayList<>(names.size()); for (String name : names) { try { - entries.add(new MemoryChildNodeEntry(name, node.getChildNode(name))); + NodeState childNode = node.getChildNode(name); + if (childNode.exists()) { + entries.add(new MemoryChildNodeEntry(name, childNode)); + } } catch (Throwable t) { if (catchExceptions) { String message = "Cannot read node " + basePath + "/" + name + " : " + t.getMessage(); diff --git a/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/json/JsonSerializerTest.java b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/json/JsonSerializerTest.java index 20b1e4a9ef3..254fc537702 100644 --- a/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/json/JsonSerializerTest.java +++ b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/json/JsonSerializerTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.jackrabbit.oak.api.Type; @@ -41,8 +40,11 @@ public void childOrder() throws Exception{ builder.child("a"); builder.child("b"); builder.child("c"); - List expectedOrder = Arrays.asList("a", "c", "b"); - builder.setProperty(":childOrder", expectedOrder, Type.NAMES); + builder.child("d"); + builder.setProperty(":childOrder", List.of("a", "c", "b", "d"), Type.NAMES); + + // A removed child should not be included in the output + builder.getChildNode("c").remove(); NodeState state = builder.getNodeState(); String json = serialize(state); @@ -60,7 +62,7 @@ public void childOrder() throws Exception{ } while (reader.matches(',')); - assertEquals(expectedOrder, childNames); + assertEquals(List.of("a", "b", "d"), childNames); } private String serialize(NodeState nodeState){