jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1453376 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
Date Wed, 06 Mar 2013 15:13:20 GMT
Author: mduerig
Date: Wed Mar  6 15:13:20 2013
New Revision: 1453376

URL: http://svn.apache.org/r1453376
Log:
OAK-678: Access to disconnected MemoryNodeBuilder should throw IllegalStateException

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1453376&r1=1453375&r2=1453376&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Mar  6 15:13:20 2013
@@ -190,13 +190,18 @@ public class MemoryNodeBuilder implement
 
     /**
      * Determine whether this child exists at its direct parent.
-     * @return  {@code true} iff this child exists at its direct parent.
+     * @return {@code true} iff this child exists at its direct parent.
      */
     private boolean exists() {
-        // No need to check the base state if write state is null. The fact that we have
this
-        // builder instance proofs that this child existed at some point as it must have
been
-        // retrieved from the base state.
-        return isRoot() || parent.writeState == null || parent.writeState.hasChildNode(name);
+        if (isRoot()) {
+            return true;
+        }
+        else if (parent.writeState == null) {
+            return parent.baseState != null && parent.baseState.hasChildNode(name);
+        }
+        else {
+            return parent.writeState.hasChildNode(name);
+        }
     }
 
     /**
@@ -206,18 +211,19 @@ public class MemoryNodeBuilder implement
     private boolean updateReadState() {
         if (revision != root.revision) {
             assert(!isRoot()); // root never gets here since revision == root.revision
-            if (!exists()) {
-                return false;
-            }
-            parent.updateReadState();
 
-            // The builder could have been reset, need to re-get base state
-            baseState = parent.getBaseState(name);
+            if (parent.updateReadState() && exists()) {
+                // The builder could have been reset, need to re-get base state
+                baseState = parent.getBaseState(name);
 
-            // ... same for the write state
-            writeState = parent.getWriteState(name);
+                // ... same for the write state
+                writeState = parent.getWriteState(name);
+
+                revision = root.revision;
+                return true;
+            }
 
-            revision = root.revision;
+            return false;
         }
         return writeState != null || baseState != null;
     }
@@ -238,8 +244,8 @@ public class MemoryNodeBuilder implement
     private MutableNodeState write(long newRevision, boolean reconnect) {
         // make sure that all revision numbers up to the root gets updated
         if (!isRoot()) {
-            checkState(reconnect || exists(), "This node has been removed");
             parent.write(newRevision, reconnect);
+            checkState(reconnect || exists(), "This node has been removed");
         }
 
         if (writeState == null || revision != root.revision) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java?rev=1453376&r1=1453375&r2=1453376&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
Wed Mar  6 15:13:20 2013
@@ -182,4 +182,14 @@ public class MemoryNodeBuilderTest {
         assertEquals(x.getBaseState(), x.getNodeState());
     }
 
+    @Test(expected = IllegalStateException.class)
+    public void testReadOnRemovedNode() {
+        NodeBuilder root = new MemoryNodeBuilder(BASE);
+        NodeBuilder m = root.child("m");
+        NodeBuilder n = m.child("n");
+
+        root.removeNode("m");
+        n.hasChildNode("any");
+    }
+
 }



Mime
View raw message