Author: mreutegg
Date: Mon Mar 30 09:50:47 2015
New Revision: 1670030

URL: http://svn.apache.org/r1670030
Log:
OAK-2695: DocumentNodeStore.dispatch() may pass null to NodeStateDiff

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1670030&r1=1670029&r2=1670030&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 Mon Mar 30 09:50:47 2015
@@ -168,18 +168,7 @@ public class DocumentNodeState extends A
     @Nonnull
     @Override
     public NodeState getChildNode(@Nonnull String name) {
-        if (!hasChildren) {
-            checkValidName(name);
-            return EmptyNodeState.MISSING_NODE;
-        }
-        String p = PathUtils.concat(getPath(), name);
-        DocumentNodeState child = store.getNode(p, lastRevision);
-        if (child == null) {
-            checkValidName(name);
-            return EmptyNodeState.MISSING_NODE;
-        } else {
-            return child;
-        }
+        return getChildNode(name, lastRevision);
     }
 
     @Override
@@ -282,6 +271,23 @@ public class DocumentNodeState extends A
         return super.compareAgainstBaseState(base, diff);
     }
 
+    @Nonnull
+    NodeState getChildNode(@Nonnull String name,
+                           @Nonnull Revision revision) {
+        if (!hasChildren) {
+            checkValidName(name);
+            return EmptyNodeState.MISSING_NODE;
+        }
+        String p = PathUtils.concat(getPath(), name);
+        DocumentNodeState child = store.getNode(p, checkNotNull(revision));
+        if (child == null) {
+            checkValidName(name);
+            return EmptyNodeState.MISSING_NODE;
+        } else {
+            return child;
+        }
+    }
+
     void setProperty(String propertyName, String value) {
         if (value == null) {
             properties.remove(propertyName);

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1670030&r1=1670029&r2=1670030&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Mon Mar 30 09:50:47 2015
@@ -1905,14 +1905,14 @@ public final class DocumentNodeStore
                     while (t.read() != '}') {
                         // skip properties
                     }
-                    NodeState child = getNode(concat(node.getPath(), name), 
nodeRev);
-                    continueComparison = diff.childNodeAdded(name, child);
+                    continueComparison = diff.childNodeAdded(name,
+                            node.getChildNode(name, nodeRev));
                     break;
                 }
                 case '-': {
                     String name = unshareString(t.readString());
-                    NodeState child = getNode(concat(base.getPath(), name), 
baseRev);
-                    continueComparison = diff.childNodeDeleted(name, child);
+                    continueComparison = diff.childNodeDeleted(name,
+                            base.getChildNode(name, baseRev));
                     break;
                 }
                 case '^': {
@@ -1920,10 +1920,9 @@ public final class DocumentNodeStore
                     t.read(':');
                     if (t.matches('{')) {
                         t.read('}');
-                        NodeState nodeChild = getNode(concat(node.getPath(), 
name), nodeRev);
-                        NodeState baseChild = getNode(concat(base.getPath(), 
name), baseRev);
-                        continueComparison = diff.childNodeChanged(
-                                name, baseChild, nodeChild);
+                        continueComparison = diff.childNodeChanged(name,
+                                base.getChildNode(name, baseRev),
+                                node.getChildNode(name, nodeRev));
                     } else if (t.matches('[')) {
                         // ignore multi valued property
                         while (t.read() != ']') {

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1670030&r1=1670029&r2=1670030&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 Mon Mar 30 09:50:47 2015
@@ -72,6 +72,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -1217,6 +1218,32 @@ public class DocumentNodeStoreTest {
         }
     }
 
+    // OAK-2695
+    @Test
+    public void dispatch() throws Exception {
+        DocumentNodeStore ns = new DocumentMK.Builder().getNodeStore();
+
+        Revision from = ns.getHeadRevision();
+        NodeBuilder builder = ns.getRoot().builder();
+        builder.child("test");
+        merge(ns, builder);
+        Revision to = ns.getHeadRevision();
+
+        DiffCache.Entry entry = ns.getDiffCache().newEntry(from, to);
+        entry.append("/", "-\"foo\"");
+        entry.done();
+
+        ns.compare(ns.getRoot(), ns.getRoot(from), new DefaultNodeStateDiff() {
+            @Override
+            public boolean childNodeDeleted(String name, NodeState before) {
+                assertNotNull(before);
+                return true;
+            }
+        });
+
+        ns.dispose();
+    }
+
     private void doSomeChange(NodeStore ns) throws CommitFailedException {
         NodeBuilder b = ns.getRoot().builder();
         b.setProperty("count", System.currentTimeMillis());


Reply via email to