Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java (revision 1875917) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java (working copy) @@ -40,6 +40,7 @@ import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; import org.apache.jackrabbit.oak.spi.commit.CommitHook; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.state.ApplyDiff; import org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -496,9 +497,13 @@ branchState = new Unmodified(base); } else { int numChanges = countChanges(base, root); - head = newModifiedDocumentNodeState(root); if (numChanges > updateLimit) { + head = newModifiedDocumentNodeState(root); persist(); + } else { + NodeBuilder builder = new MemoryNodeBuilder(base); + root.compareAgainstBaseState(base, new ApplyDiff(builder)); + head = newModifiedDocumentNodeState(builder.getNodeState()); } } } Index: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java =================================================================== --- oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java (revision 1875917) +++ oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java (working copy) @@ -16,7 +16,9 @@ */ package org.apache.jackrabbit.oak.plugins.document; +import org.apache.jackrabbit.oak.json.JsopDiff; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeState; import org.junit.Rule; import org.junit.Test; @@ -103,4 +105,21 @@ // expected } } + + @Test + public void noopChanges() throws Exception { + // Run this test with JVM argument: -Xss256k + // It should not produce a StackOverflow exception + DocumentNodeStore ns = builderProvider.newBuilder().setUpdateLimit(10).getNodeStore(); + NodeBuilder builder = ns.getRoot().builder(); + builder.child("a").setProperty("p", 1); + merge(ns, builder); + NodeState root = ns.getRoot(); + builder = root.builder(); + builder.child("b"); + for (int i = 0; i < ns.getUpdateLimit() * 2000; i++) { + builder.child("a").setProperty("p", 1); + } + builder.getNodeState().compareAgainstBaseState(root, new JsopDiff()); + } }