jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1464516 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ oak-core/src/main/java/org/...
Date Thu, 04 Apr 2013 13:12:23 GMT
Author: jukka
Date: Thu Apr  4 13:12:22 2013
New Revision: 1464516

URL: http://svn.apache.org/r1464516
Log:
OAK-709: Consider moving permission evaluation to the node state level

Make NodeState.getChildNode() @Nonnull by adding a NodeState.exists() method

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java Thu Apr  4 13:12:22 2013
@@ -113,7 +113,7 @@ public final class ImmutableTree extends
     @Override
     public ImmutableTree getChild(@Nonnull String name) {
         NodeState child = getNodeState().getChildNode(name);
-        if (child != null) {
+        if (child.exists()) {
             return new ImmutableTree(this, name, child);
         } else {
             return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java Thu Apr  4 13:12:22 2013
@@ -130,7 +130,7 @@ public class ReadOnlyTree implements Tre
     @Override
     public ReadOnlyTree getChild(@Nonnull String name) {
         NodeState child = state.getChildNode(name);
-        if (child != null) {
+        if (child.exists()) {
             return new ReadOnlyTree(this, name, child);
         } else {
             return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java Thu Apr  4 13:12:22 2013
@@ -96,8 +96,12 @@ public class TreeImpl implements Tree {
         this.name = checkNotNull(name);
         this.nodeBuilder = parent.getNodeBuilder().child(name);
         this.pendingMoves = checkNotNull(pendingMoves);
-        // readstatus is ALLOW_ALL for new items
-        readStatus = (getBaseState() == null) ? ReadStatus.ALLOW_ALL : ReadStatus.getChildStatus(parent.readStatus);
+
+        if (getBaseState().exists()) {
+            readStatus = ReadStatus.getChildStatus(parent.readStatus);
+        } else {
+            readStatus = ReadStatus.ALLOW_ALL; // new items are always readable
+        }
     }
 
     @Override
@@ -153,7 +157,7 @@ public class TreeImpl implements Tree {
         }
 
         NodeState parentBase = getBaseState();
-        PropertyState base = parentBase == null ? null : parentBase.getProperty(name);
+        PropertyState base = parentBase.getProperty(name);
 
         if (base == null) {
             return Status.NEW;
@@ -418,21 +422,16 @@ public class TreeImpl implements Tree {
     }
 
     /**
-     * The node state this tree is based on. {@code null} if this is a newly added tree.
+     * The (possibly non-existent) node state this tree is based on.
      * @return the base node state of this tree
      */
-    @CheckForNull
+    @Nonnull
     final NodeState getBaseState() {
         if (parent == null) {
             return root.getBaseState();
+        } else {
+            return parent.getBaseState().getChildNode(name);
         }
-
-        NodeState parentBase = parent.getBaseState();
-        if (parentBase != null) {
-            return parentBase.getChildNode(name);
-        }
-
-        return null;
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java Thu Apr  4 13:12:22 2013
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.kernel
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
 
 import java.lang.reflect.InvocationHandler;
@@ -63,6 +64,8 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * Basic {@link NodeState} implementation based on the {@link MicroKernel}
  * interface. This class makes an attempt to load data lazily.
@@ -219,6 +222,11 @@ public final class KernelNodeState exten
     }
 
     @Override
+    public boolean exists() {
+        return true;
+    }
+
+    @Override
     public long getPropertyCount() {
         init();
         return properties.size();
@@ -247,12 +255,13 @@ public final class KernelNodeState exten
         checkNotNull(name);
         init();
         return childNames.contains(name)
-                || childNodeCount > MAX_CHILD_NODE_NAMES && getChildNode(name) != null;
+                || (childNodeCount > MAX_CHILD_NODE_NAMES
+                        && getChildNode(name).exists());
     }
 
     @Override
     public NodeState getChildNode(String name) {
-        checkNotNull(name);
+        // checkArgument(!checkNotNull(name).isEmpty()); // TODO: check in higher level
         init();
         String childPath = null;
         if (childNames.contains(name)) {
@@ -266,7 +275,7 @@ public final class KernelNodeState exten
                 if (state != NULL) {
                     return state;
                 } else {
-                    return null;
+                    return MISSING_NODE;
                 }
             }
             // not able to tell from cache if node exists
@@ -278,7 +287,7 @@ public final class KernelNodeState exten
             }
         }
         if (childPath == null) {
-            return null;
+            return MISSING_NODE;
         }
         try {
             return cache.get(revision + childPath);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java Thu Apr  4 13:12:22 2013
@@ -99,16 +99,16 @@ class KernelNodeStoreBranch extends Abst
     @Override
     public boolean move(String source, String target) {
         checkNotMerged();
-        if (getNode(source) == null) {
+        if (!getNode(source).exists()) {
             // source does not exist
             return false;
         }
         NodeState destParent = getNode(getParentPath(target));
-        if (destParent == null) {
+        if (!destParent.exists()) {
             // parent of destination does not exist
             return false;
         }
-        if (destParent.getChildNode(getName(target)) != null) {
+        if (destParent.getChildNode(getName(target)).exists()) {
             // destination exists already
             return false;
         }
@@ -120,16 +120,16 @@ class KernelNodeStoreBranch extends Abst
     @Override
     public boolean copy(String source, String target) {
         checkNotMerged();
-        if (getNode(source) == null) {
+        if (!getNode(source).exists()) {
             // source does not exist
             return false;
         }
         NodeState destParent = getNode(getParentPath(target));
-        if (destParent == null) {
+        if (!destParent.exists()) {
             // parent of destination does not exist
             return false;
         }
-        if (destParent.getChildNode(getName(target)) != null) {
+        if (destParent.getChildNode(getName(target)).exists()) {
             // destination exists already
             return false;
         }
@@ -213,11 +213,7 @@ class KernelNodeStoreBranch extends Abst
         NodeState node = getHead();
         for (String name : elements(path)) {
             node = node.getChildNode(name);
-            if (node == null) {
-                break;
-            }
         }
-
         return node;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java Thu Apr  4 13:12:22 2013
@@ -118,7 +118,7 @@ public class IndexUtils implements Index
     public static List<IndexDefinition> buildIndexDefinitions(NodeState state,
                                                               String indexConfigPath, String typeFilter) {
         NodeState definitions = state.getChildNode(INDEX_DEFINITIONS_NAME);
-        if (definitions == null) {
+        if (!definitions.exists()) {
             return Collections.emptyList();
         }
         indexConfigPath = concat(indexConfigPath, INDEX_DEFINITIONS_NAME);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java Thu Apr  4 13:12:22 2013
@@ -119,7 +119,7 @@ public class Property2IndexLookup {
     @Nullable
     private static NodeState getIndexDataNode(NodeState node, String propertyName, Filter filter) {
         NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
-        if (state == null) {
+        if (!state.exists()) {
             return null;
         }
         String filterNodeType = null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java Thu Apr  4 13:12:22 2013
@@ -149,7 +149,7 @@ public class ContentMirrorStoreStrategy 
                 } else {
                     for (String p : values) {
                         NodeState property = index.getChildNode(p);
-                        if (property != null) {
+                        if (property.exists()) {
                             // we have an entry for this value, so use it
                             it.enqueue(Iterators.singletonIterator(
                                     new MemoryChildNodeEntry("", property)));
@@ -181,7 +181,7 @@ public class ContentMirrorStoreStrategy 
                     break;
                 }
                 NodeState s = index.getChildNode(p);
-                if (s != null) {
+                if (s.exists()) {
                     CountingNodeVisitor v = new CountingNodeVisitor(max);
                     v.visit(s);
                     count += v.getEstimatedCount();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java Thu Apr  4 13:12:22 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Collections;
 
 import javax.annotation.CheckForNull;
@@ -28,14 +31,24 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
 /**
- * Singleton instance of an empty node state, i.e. one with neither
- * properties nor child nodes.
+ * Singleton instances of empty and non-existent node states, i.e. ones
+ * with neither properties nor child nodes.
  */
 public final class EmptyNodeState implements NodeState {
 
-    public static final NodeState EMPTY_NODE = new EmptyNodeState();
+    public static final NodeState EMPTY_NODE = new EmptyNodeState(true);
+
+    public static final NodeState MISSING_NODE = new EmptyNodeState(false);
+
+    private final boolean exists;
+
+    private EmptyNodeState(boolean exists) {
+        this.exists = exists;
+    }
 
-    private EmptyNodeState() {
+    @Override
+    public boolean exists() {
+        return exists;
     }
 
     @Override
@@ -60,12 +73,14 @@ public final class EmptyNodeState implem
 
     @Override
     public boolean hasChildNode(@Nonnull String name) {
+        checkArgument(!checkNotNull(name).isEmpty());
         return false;
     }
 
-    @Override @CheckForNull
+    @Override @Nonnull
     public NodeState getChildNode(@Nonnull String name) {
-        return null;
+        checkArgument(!checkNotNull(name).isEmpty());
+        return MISSING_NODE;
     }
 
     @Override
@@ -85,7 +100,7 @@ public final class EmptyNodeState implem
 
     @Override
     public void compareAgainstBaseState(NodeState base, NodeStateDiff diff) {
-        if (base != EMPTY_NODE) {
+        if (base != EMPTY_NODE && base.exists()) {
             for (PropertyState before : base.getProperties()) {
                 diff.propertyDeleted(before);
             }
@@ -97,7 +112,7 @@ public final class EmptyNodeState implem
 
     public static void compareAgainstEmptyState(
             NodeState state, NodeStateDiff diff) {
-        if (state != EMPTY_NODE) {
+        if (state != EMPTY_NODE && state.exists()) {
             for (PropertyState after : state.getProperties()) {
                 diff.propertyAdded(after);
             }
@@ -114,8 +129,8 @@ public final class EmptyNodeState implem
     }
 
     public boolean equals(Object object) {
-        if (object == EMPTY_NODE) {
-            return true;
+        if (object == EMPTY_NODE || object == MISSING_NODE) {
+            return exists == (object == EMPTY_NODE);
         } else if (object instanceof NodeState) {
             NodeState that = (NodeState) object;
             return that.getPropertyCount() == 0
@@ -128,4 +143,5 @@ public final class EmptyNodeState implem
     public int hashCode() {
         return 0;
     }
+
 }

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=1464516&r1=1464515&r2=1464516&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 Thu Apr  4 13:12:22 2013
@@ -31,9 +31,11 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.with;
 import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.withNodes;
 import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.withProperties;
@@ -96,7 +98,7 @@ public class MemoryNodeBuilder implement
     private long revision;
 
     /**
-     * The base state of this builder, or {@code null} if this builder
+     * The base state of this builder, possibly non-existent if this builder
      * represents a new node that didn't yet exist in the base content tree.
      */
     private NodeState baseState;
@@ -120,7 +122,7 @@ public class MemoryNodeBuilder implement
         this.root = parent.root;
         this.revision = -1;
 
-        this.baseState = null;
+        this.baseState = parent.baseState.getChildNode(name);
         this.writeState = null;
     }
 
@@ -143,7 +145,7 @@ public class MemoryNodeBuilder implement
     private boolean classInvariants() {
         boolean rootHasNoParent = isRoot() == (parent == null);
         boolean rootHasWriteState = root.writeState != null;
-        boolean baseStateOrWriteStateNotNull = baseState != null || writeState != null;
+        boolean baseStateOrWriteStateNotNull = baseState.exists() || writeState != null;
 
         return rootHasNoParent && rootHasWriteState && baseStateOrWriteStateNotNull;
     }
@@ -158,11 +160,7 @@ public class MemoryNodeBuilder implement
      * @return  base state of the child
      */
     private NodeState getBaseState(String name) {
-        if (baseState != null) {
-            return baseState.getChildNode(name);
-        } else {
-            return null;
-        }
+        return baseState.getChildNode(name);
     }
 
     /**
@@ -172,7 +170,7 @@ public class MemoryNodeBuilder implement
      * @return  {@code true} iff the base state has a child of the given name.
      */
     private boolean hasBaseState(String name) {
-        return baseState != null && baseState.hasChildNode(name);
+        return baseState.hasChildNode(name);
     }
 
     /**
@@ -196,11 +194,9 @@ public class MemoryNodeBuilder implement
     private boolean exists() {
         if (isRoot()) {
             return true;
-        }
-        else if (parent.writeState == null) {
-            return parent.baseState != null && parent.baseState.hasChildNode(name);
-        }
-        else {
+        } else if (parent.writeState == null) {
+            return parent.baseState.hasChildNode(name);
+        } else {
             return parent.writeState.hasChildNode(name);
         }
     }
@@ -226,7 +222,7 @@ public class MemoryNodeBuilder implement
 
             return false;
         }
-        return writeState != null || baseState != null;
+        return writeState != null || baseState.exists();
     }
 
     @Nonnull
@@ -258,7 +254,7 @@ public class MemoryNodeBuilder implement
             writeState = parent.getWriteState(name);
             if (writeState == null) {
                 if (exists()) {
-                    assert baseState != null;
+                    assert baseState.exists();
                     writeState = new MutableNodeState(baseState);
                 }
                 else {
@@ -340,7 +336,8 @@ public class MemoryNodeBuilder implement
                 if (pState == null) {
                     return true;
                 }
-                if (baseState == null || !pState.equals(baseState.getProperty(p.getKey()))) {
+                if (!baseState.exists()
+                        || !pState.equals(baseState.getProperty(p.getKey()))) {
                     return true;
                 }
             }
@@ -354,7 +351,7 @@ public class MemoryNodeBuilder implement
         if (writeState != null) {
             return writeState.snapshot();
         } else {
-            assert baseState != null;
+            assert baseState.exists();
             return baseState;
         }
     }
@@ -407,7 +404,7 @@ public class MemoryNodeBuilder implement
     public NodeBuilder removeNode(String name) {
         write();
 
-        if (writeState.base.getChildNode(name) != null) {
+        if (writeState.base.getChildNode(name).exists()) {
             writeState.nodes.put(name, null);
         } else {
             writeState.nodes.remove(name);
@@ -505,15 +502,6 @@ public class MemoryNodeBuilder implement
         private final Map<String, MutableNodeState> nodes =
                 Maps.newHashMap();
 
-        /**
-         * Determine whether the a node with the given name was removed
-         * @param name  name of the node
-         * @return  {@code true}  iff a node with the given name was removed
-         */
-        private boolean isRemoved(String name) {
-            return nodes.containsKey(name) && nodes.get(name) == null;
-        }
-
         public MutableNodeState(NodeState base) {
             if (base != null) {
                 this.base = base;
@@ -552,7 +540,7 @@ public class MemoryNodeBuilder implement
                 Map.Entry<String, MutableNodeState> entry = iterator.next();
                 MutableNodeState cstate = entry.getValue();
                 NodeState cbase = newBase.getChildNode(entry.getKey());
-                if (cbase == null || cstate == null) {
+                if (!cbase.exists() || cstate == null) {
                     iterator.remove();
                 } else {
                     cstate.reset(cbase);
@@ -563,6 +551,11 @@ public class MemoryNodeBuilder implement
         //-----------------------------------------------------< NodeState >--
 
         @Override
+        public boolean exists() {
+            return true;
+        }
+
+        @Override
         public long getPropertyCount() {
             return withProperties(base, properties).getPropertyCount();
         }
@@ -586,12 +579,14 @@ public class MemoryNodeBuilder implement
         @Override
         public boolean hasChildNode(String name) {
             checkNotNull(name);
+            // checkArgument(!name.isEmpty()); TODO: should be caught earlier
             return withNodes(base, nodes).hasChildNode(name);
         }
 
         @Override
         public NodeState getChildNode(String name) {
             checkNotNull(name);
+            checkArgument(!name.isEmpty());
             return withNodes(base, nodes).getChildNode(name); // mutable
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java Thu Apr  4 13:12:22 2013
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
@@ -56,6 +59,11 @@ class MemoryNodeState extends AbstractNo
     }
 
     @Override
+    public boolean exists() {
+        return true;
+    }
+
+    @Override
     public PropertyState getProperty(String name) {
         return properties.get(name);
     }
@@ -72,14 +80,19 @@ class MemoryNodeState extends AbstractNo
 
     @Override
     public boolean hasChildNode(String name) {
-        checkNotNull(name);
+        checkArgument(!checkNotNull(name).isEmpty());
         return nodes.containsKey(name);
     }
 
     @Override
     public NodeState getChildNode(String name) {
-        checkNotNull(name);
-        return nodes.get(name);
+        checkArgument(!checkNotNull(name).isEmpty());
+        NodeState state = nodes.get(name);
+        if (state != null) {
+            return state;
+        } else {
+            return MISSING_NODE;
+        }
     }
 
     @Override
@@ -104,6 +117,11 @@ class MemoryNodeState extends AbstractNo
      */
     @Override
     public void compareAgainstBaseState(NodeState base, NodeStateDiff diff) {
+        if (base == EMPTY_NODE || !base.exists()) {
+            EmptyNodeState.compareAgainstEmptyState(this, diff);
+            return;
+        }
+
         Map<String, PropertyState> newProperties =
                 new HashMap<String, PropertyState>(properties);
         for (PropertyState before : base.getProperties()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java Thu Apr  4 13:12:22 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Predicates.in;
 import static com.google.common.base.Predicates.not;
@@ -24,6 +25,7 @@ import static com.google.common.collect.
 import static com.google.common.collect.Iterables.concat;
 import static com.google.common.collect.Iterables.filter;
 import static com.google.common.collect.Maps.filterValues;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry.iterable;
 
 import java.util.Map;
@@ -142,6 +144,11 @@ public class ModifiedNodeState extends A
     }
 
     @Override
+    public boolean exists() {
+        return true;
+    }
+
+    @Override
     public long getPropertyCount() {
         long count = base.getPropertyCount();
 
@@ -191,7 +198,7 @@ public class ModifiedNodeState extends A
         long count = base.getChildNodeCount();
 
         for (Map.Entry<String, ? extends NodeState> entry : nodes.entrySet()) {
-            if (base.getChildNode(entry.getKey()) != null) {
+            if (base.getChildNode(entry.getKey()).exists()) {
                 count--;
             }
             if (entry.getValue() != null) {
@@ -204,12 +211,12 @@ public class ModifiedNodeState extends A
 
     @Override
     public boolean hasChildNode(String name) {
-        checkNotNull(name);
+        // checkArgument(!checkNotNull(name).isEmpty()); // TODO: should be caught earlier
         NodeState child = nodes.get(name);
         if (child != null) {
             return true;
         } else if (nodes.containsKey(name)) {
-            return false; // removed
+            return false;
         } else {
             return base.hasChildNode(name);
         }
@@ -217,12 +224,12 @@ public class ModifiedNodeState extends A
 
     @Override
     public NodeState getChildNode(String name) {
-        checkNotNull(name);
+        checkArgument(!checkNotNull(name).isEmpty());
         NodeState child = nodes.get(name);
         if (child != null) {
             return child;
         } else if (nodes.containsKey(name)) {
-            return null; // removed
+            return MISSING_NODE;
         } else {
             return base.getChildNode(name);
         }
@@ -327,11 +334,11 @@ public class ModifiedNodeState extends A
             String name = entry.getKey();
             NodeState before = base.getChildNode(name);
             NodeState after = entry.getValue();
-            if (before == null && after == null) {
-                // do nothing
-            } else if (after == null) {
-                diff.childNodeDeleted(name, before);
-            } else if (before == null) {
+            if (after == null) {
+                if (before.exists()) {
+                    diff.childNodeDeleted(name, before);
+                }
+            } else if (!before.exists()) {
                 diff.childNodeAdded(name, after);
             } else if (!before.equals(after)) {
                 diff.childNodeChanged(name, before, after);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java Thu Apr  4 13:12:22 2013
@@ -51,32 +51,28 @@ class EffectiveType {
         for (NodeState type : types) {
             NodeState properties =
                     type.getChildNode("oak:namedPropertyDefinitions");
-            if (properties != null) {
-                for (ChildNodeEntry entry : properties.getChildNodeEntries()) {
-                    String name = entry.getName();
-                    if ("oak:primaryType".equals(name)) {
-                        name = JCR_PRIMARYTYPE;
-                    } else if ("oak:mixinTypes".equals(name)) {
-                        name = JCR_MIXINTYPES;
-                    } else if ("oak:uuid".equals(name)) {
-                        name = JCR_UUID;
-                    }
-                    if (node.getProperty(name) == null
-                            && isMandatory(name, entry.getNodeState())) {
-                        builder.add(name);
-                    }
+            for (ChildNodeEntry entry : properties.getChildNodeEntries()) {
+                String name = entry.getName();
+                if ("oak:primaryType".equals(name)) {
+                    name = JCR_PRIMARYTYPE;
+                } else if ("oak:mixinTypes".equals(name)) {
+                    name = JCR_MIXINTYPES;
+                } else if ("oak:uuid".equals(name)) {
+                    name = JCR_UUID;
+                }
+                if (node.getProperty(name) == null
+                        && isMandatory(name, entry.getNodeState())) {
+                    builder.add(name);
                 }
             }
 
             NodeState childNodes =
                     type.getChildNode("oak:namedChildNodeDefinitions");
-            if (childNodes != null) {
-                for (ChildNodeEntry entry : childNodes.getChildNodeEntries()) {
-                    String name = entry.getName();
-                    if (!node.hasChildNode(name)
-                            && isMandatory(name, entry.getNodeState())) {
-                        builder.add(name);
-                    }
+            for (ChildNodeEntry entry : childNodes.getChildNodeEntries()) {
+                String name = entry.getName();
+                if (!node.hasChildNode(name)
+                        && isMandatory(name, entry.getNodeState())) {
+                    builder.add(name);
                 }
             }
         }
@@ -117,22 +113,17 @@ class EffectiveType {
         // Find matching named property definition
         for (NodeState type : types) {
             NodeState named = type.getChildNode("oak:namedPropertyDefinitions");
-            if (named != null) {
-                NodeState definitions = named.getChildNode(escapedName);
-                if (definitions != null) {
-                    NodeState definition = definitions.getChildNode(definedType);
-                    if (definition == null) {
-                        definition = definitions.getChildNode(undefinedType);
-                    }
-                    if (definition != null) {
-                        return definition;
+            NodeState definitions = named.getChildNode(escapedName);
+            NodeState definition = definitions.getChildNode(definedType);
+            if (!definition.exists()) {
+                definition = definitions.getChildNode(undefinedType);
+            }
+            if (definition.exists()) {
+                return definition;
 // TODO: Fall back to residual definitions until we have consensus on OAK-709
-//                    } else {
-//                        throw new ConstraintViolationException(
-//                                "No matching definition found for property "
-//                                        + propertyName);
-                    }
-                }
+//          } else {
+//              throw new ConstraintViolationException(
+//                    "No matching definition found for property " + propertyName);
             }
         }
 
@@ -140,14 +131,12 @@ class EffectiveType {
         for (NodeState type : types) {
             NodeState residual =
                     type.getChildNode("oak:residualPropertyDefinitions");
-            if (residual != null) {
-                NodeState definition = residual.getChildNode(definedType);
-                if (definition == null) {
-                    definition = residual.getChildNode(undefinedType);
-                }
-                if (definition != null) {
-                    return definition;
-                }
+            NodeState definition = residual.getChildNode(definedType);
+            if (!definition.exists()) {
+                definition = residual.getChildNode(undefinedType);
+            }
+            if (definition.exists()) {
+                return definition;
             }
         }
 
@@ -180,20 +169,17 @@ class EffectiveType {
         // Find matching named child node definition
         for (NodeState type : types) {
             NodeState named = type.getChildNode("oak:namedChildNodeDefinitions");
-            if (named != null) {
-                NodeState definitions = named.getChildNode(nodeName);
-                if (definitions != null) {
-                    for (String typeName : nodeType) {
-                        NodeState definition = definitions.getChildNode(typeName);
-                        if (definition != null) {
-                            return definition;
-                        }
+            NodeState definitions = named.getChildNode(nodeName);
+            if (definitions.exists()) {
+                for (String typeName : nodeType) {
+                    NodeState definition = definitions.getChildNode(typeName);
+                    if (definition.exists()) {
+                        return definition;
                     }
-
-// TODO: Fall back to residual definitions until we have consensus on OAK-709
-//                    throw new ConstraintViolationException(
-//                            "Incorrect node type of child node " + nodeName);
                 }
+// TODO: Fall back to residual definitions until we have consensus on OAK-709
+//              throw new ConstraintViolationException(
+//                      "Incorrect node type of child node " + nodeName);
             }
         }
 
@@ -201,10 +187,10 @@ class EffectiveType {
         for (NodeState type : types) {
             NodeState residual =
                     type.getChildNode("oak:residualChildNodeDefinitions");
-            if (residual != null) {
+            if (residual.exists()) {
                 for (String typeName : nodeType) {
                     NodeState definition = residual.getChildNode(typeName);
-                    if (definition != null) {
+                    if (definition.exists()) {
                         return definition;
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java Thu Apr  4 13:12:22 2013
@@ -20,7 +20,6 @@ import static com.google.common.base.Pre
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
 
 import java.util.LinkedList;
@@ -149,9 +148,6 @@ public abstract class ReadOnlyNodeTypeMa
         NodeState typesNode = root;
         for (String name : PathUtils.elements(NODE_TYPES_PATH)) {
             typesNode = typesNode.getChildNode(name);
-            if (typesNode == null) {
-                typesNode = EMPTY_NODE;
-            }
         }
 
         final Tree typesTree = new ReadOnlyTree(typesNode);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java Thu Apr  4 13:12:22 2013
@@ -246,7 +246,7 @@ class TypeEditor extends DefaultEditor {
             names.add(name);
 
             NodeState type = types.getChildNode(name);
-            if (type == null) {
+            if (!type.exists()) {
                 throw constraintViolation(
                         "Primary node type " + name + " does not exist");
             } else if (getBoolean(type, JCR_ISMIXIN)) {
@@ -266,7 +266,7 @@ class TypeEditor extends DefaultEditor {
             for (String name : mixins.getValue(NAMES)) {
                 if (names.add(name)) {
                     NodeState type = types.getChildNode(name);
-                    if (type == null) {
+                    if (!type.exists()) {
                         throw constraintViolation(
                                 "Mixin node type " + name + " does not exist");
                     } else if (!getBoolean(type, JCR_ISMIXIN)) {
@@ -292,7 +292,7 @@ class TypeEditor extends DefaultEditor {
                 for (String name : supertypes.getValue(NAMES)) {
                     if (names.add(name)) {
                         NodeState supertype = types.getChildNode(name);
-                        if (supertype != null) {
+                        if (supertype.exists()) {
                             list.add(supertype);
                             queue.add(supertype);
                         } else {
@@ -306,7 +306,7 @@ class TypeEditor extends DefaultEditor {
         // always include nt:base
         if (names.add(NT_BASE)) {
             NodeState base = types.getChildNode(NT_BASE);
-            if (base != null) {
+            if (base.exists()) {
                 list.add(base);
             } else {
                 // TODO: ignore/warning/error?

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java Thu Apr  4 13:12:22 2013
@@ -35,13 +35,12 @@ public class TypeEditorProvider implemen
     public Editor getRootEditor(
             NodeState before, NodeState after, NodeBuilder builder) {
         NodeState system = after.getChildNode(JCR_SYSTEM);
-        if (system != null) {
-            NodeState types = system.getChildNode(JCR_NODE_TYPES);
-            if (types != null) {
-                return new VisibleEditor(new TypeEditor(types));
-            }
+        NodeState types = system.getChildNode(JCR_NODE_TYPES);
+        if (types.exists()) {
+            return new VisibleEditor(new TypeEditor(types));
+        } else {
+            return null;
         }
-        return null;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java Thu Apr  4 13:12:22 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
@@ -69,6 +70,11 @@ class SegmentNodeState extends AbstractN
     }
 
     @Override
+    public boolean exists() {
+        return true;
+    }
+
+    @Override
     public long getPropertyCount() {
         return getTemplate().getPropertyCount();
     }
@@ -91,12 +97,14 @@ class SegmentNodeState extends AbstractN
 
     @Override
     public boolean hasChildNode(String name) {
-        return getTemplate().hasChildNode(checkNotNull(name), store, recordId);
+        checkArgument(!checkNotNull(name).isEmpty());
+        return getTemplate().hasChildNode(name, store, recordId);
     }
 
     @Override @CheckForNull
     public NodeState getChildNode(String name) {
-        return getTemplate().getChildNode(checkNotNull(name), store, recordId);
+        checkArgument(!checkNotNull(name).isEmpty());
+        return getTemplate().getChildNode(name, store, recordId);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java Thu Apr  4 13:12:22 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
 
 import java.util.Arrays;
@@ -274,14 +275,14 @@ class Template {
     public NodeState getChildNode(
             String name, SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
-            return null;
+            return MISSING_NODE;
         } else if (hasManyChildNodes()) {
             MapRecord map = getChildNodeMap(store, recordId);
             RecordId childNodeId = map.getEntry(name);
             if (childNodeId != null) {
                 return new SegmentNodeState(store, childNodeId);
             } else {
-                return null;
+                return MISSING_NODE;
             }
         } else if (name.equals(childName)) {
             int offset = recordId.getOffset() + RECORD_ID_BYTES;
@@ -289,7 +290,7 @@ class Template {
             RecordId childNodeId = segment.readRecordId(offset);
             return new SegmentNodeState(store, childNodeId);
         } else {
-            return null;
+            return MISSING_NODE;
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java Thu Apr  4 13:12:22 2013
@@ -178,11 +178,10 @@ public class Cursors {
 
                     parent = node;
                     node = parent.getChildNode(name);
-
-                    if (node == null) {
-                        // nothing can match this filter, leave nodes empty
-                        return;
-                    }
+                }
+                if (!node.exists()) {
+                    // nothing can match this filter, leave nodes empty
+                    return;
                 }
             }
             Filter.PathRestriction restriction = filter.getPathRestriction();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java Thu Apr  4 13:12:22 2013
@@ -58,7 +58,7 @@ public abstract class AbstractNodeState 
 
     @Override
     public boolean hasChildNode(String name) {
-        return getChildNode(name) != null;
+        return getChildNode(name).exists();
     }
 
     @Override
@@ -102,7 +102,7 @@ public abstract class AbstractNodeState 
             String name = beforeCNE.getName();
             NodeState beforeChild = beforeCNE.getNodeState();
             NodeState afterChild = getChildNode(name);
-            if (afterChild == null) {
+            if (!afterChild.exists()) {
                 diff.childNodeDeleted(name, beforeChild);
             } else {
                 baseChildNodes.add(name);
@@ -125,6 +125,9 @@ public abstract class AbstractNodeState 
      * @return string representation
      */
     public String toString() {
+        if (!exists()) {
+            return "{N/A}";
+        }
         StringBuilder builder = new StringBuilder("{");
         String separator = " ";
         for (PropertyState property : getProperties()) {
@@ -161,6 +164,10 @@ public abstract class AbstractNodeState 
 
         NodeState other = (NodeState) that;
 
+        if (exists() != other.exists()) {
+            return false;
+        }
+
         if (getPropertyCount() != other.getPropertyCount()
                 || getChildNodeCount() != other.getChildNodeCount()) {
             return false;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java Thu Apr  4 13:12:22 2013
@@ -64,11 +64,36 @@ import org.apache.jackrabbit.oak.api.Pro
  * as {@link RuntimeException unchecked exceptions} that higher level code
  * is not expected to be able to recover from.
  * <p>
- * Since this interface exposes no higher level constructs like access
- * controls, locking, node types or even path parsing, there's no way
- * for content access to fail because of such concerns. Such functionality
- * and related checked exceptions or other control flow constructs should
- * be implemented on a higher level above this interface.
+ * Since this interface exposes no higher level constructs like locking,
+ * node types or even path parsing, there's no way for content access to
+ * fail because of such concerns. Such functionality and related checked
+ * exceptions or other control flow constructs should be implemented on
+ * a higher level above this interface. On the other hand read access
+ * controls <em>can</em> be implemented below this interface, in which
+ * case some content that would otherwise be accessible might not show
+ * up through such an implementation.
+ *
+ * <h2>Existence and iterability of node states</h2>
+ * <p>
+ * The {@link #getChildNode(String)} method is special in that it
+ * <em>never</em> returns a {@code null} value, even if the named child
+ * node does not exist. Instead a client should use the {@link #exists()}
+ * method on the returned child state to check whether that node exists.
+ * The purpose of this separation of concerns is to allow an implementation
+ * to lazily load content only when it's actually read instead of just
+ * traversed. It also simplifies client code by avoiding the need for many
+ * {@code null} checks when traversing paths.
+ * <p>
+ * The <em>iterability</em> of a node is a related concept to the
+ * above-mentioned existence. A node state is <em>iterable</em> if it
+ * is included in the return values of the {@link #getChildNodeCount()},
+ * {@link #getChildNodeNames()} and {@link #getChildNodeEntries()} methods.
+ * An iterable node is guaranteed to exist, though not all existing nodes
+ * are necessarily iterable.
+ * <p>
+ * Furthermore, a non-existing node is guaranteed to contain no properties
+ * or iterable child nodes. It can, however contain non-iterable children.
+ * Such scenarios are typically the result of access control restrictions.
  *
  * <h2>Decoration and virtual content</h2>
  * <p>
@@ -77,7 +102,7 @@ import org.apache.jackrabbit.oak.api.Pro
  * like for example the aggregate size of the entire subtree as an
  * extra virtual property. A virtualization, sharding or caching layer
  * could provide a composite view over multiple underlying trees.
- * Or a basic access control layer could decide to hide certain content
+ * Or a an access control layer could decide to hide certain content
  * based on specific rules. All such features need to be implemented
  * according to the API contract of this interface. A separate higher level
  * interface needs to be used if an implementation can't for example
@@ -85,8 +110,8 @@ import org.apache.jackrabbit.oak.api.Pro
  *
  * <h2>Equality and hash codes</h2>
  * <p>
- * Two node states are considered equal if and only if their properties and
- * child nodes match, regardless of ordering. The
+ * Two node states are considered equal if and only if their existence,
+ * properties and iterable child nodes match, regardless of ordering. The
  * {@link Object#equals(Object)} method needs to be implemented so that it
  * complies with this definition. And while node states are not meant for
  * use as hash keys, the {@link Object#hashCode()} method should still be
@@ -95,13 +120,21 @@ import org.apache.jackrabbit.oak.api.Pro
 public interface NodeState {
 
     /**
+     * Checks whether this node exists. See the above discussion about
+     * the existence of node states.
+     *
+     * @return {@code true} if this node exists, {@code false} if not
+     */
+    boolean exists();
+
+    /**
      * Returns the named property. The name is an opaque string and
      * is not parsed or otherwise interpreted by this method.
      * <p>
      * The namespace of properties and child nodes is shared, so if
      * this method returns a non-{@code null} value for a given
      * name, then {@link #getChildNode(String)} is guaranteed to return
-     * {@code null} for the same name.
+     * a <em>non-existing</em> {@link NodeState} for the same name.
      *
      * @param name name of the property to return
      * @return named property, or {@code null} if not found
@@ -128,7 +161,8 @@ public interface NodeState {
     Iterable<? extends PropertyState> getProperties();
 
     /**
-     * Checks whether the named child node exists.
+     * Checks whether the named child node exists. The implementation
+     * is equivalent to {@code getChildNode(name).exists()}.
      *
      * @param name name of the child node
      * @return {@code true} if the named child node exists,
@@ -137,40 +171,42 @@ public interface NodeState {
     boolean hasChildNode(@Nonnull String name);
 
     /**
-     * Returns the named child node. The name is an opaque string and
-     * is not parsed or otherwise interpreted by this method.
+     * Returns the named, possibly non-existent, child node. The name is an
+     * opaque string and is not parsed or otherwise interpreted by this method.
+     * Use the {@link #exists()} method on the returned child node to
+     * determine whether the node exists or not.
      * <p>
      * The namespace of properties and child nodes is shared, so if
-     * this method returns a non-{@code null} value for a given
-     * name, then {@link #getProperty(String)} is guaranteed to return
-     * {@code null} for the same name.
+     * this method returns an <em>existing</em> {@link NodeState} for
+     * a given name, then {@link #getProperty(String)} is guaranteed
+     * to return {@code null} for the same name.
      *
      * @param name name of the child node to return
-     * @return named child node, or {@code null} if not found
+     * @return named child node
      */
-    @CheckForNull
+    @Nonnull
     NodeState getChildNode(@Nonnull String name);
 
     /**
-     * Returns the number of child nodes of this node.
+     * Returns the number of <em>iterable</em> child nodes of this node.
      *
-     * @return number of child nodes
+     * @return number of iterable child nodes
      */
     long getChildNodeCount();
 
     /**
-     * Returns the names of all child nodes.
+     * Returns the names of all <em>iterable</em> child nodes.
      *
      * @return child node names in some stable order
      */
     Iterable<String> getChildNodeNames();
 
     /**
-     * Returns an iterable of the child node entries of this instance. Multiple
-     * iterations are guaranteed to return the child nodes in the same order,
-     * but the specific order used is implementation dependent and may change
-     * across different states of the same node.
-     * <p/>
+     * Returns the <em>iterable</em> child node entries of this instance.
+     * Multiple iterations are guaranteed to return the child nodes in
+     * the same order, but the specific order used is implementation
+     * dependent and may change across different states of the same node.
+     * <p>
      * <i>Note on cost and performance:</i> while it is possible to iterate over
      * all child {@code NodeState}s with the two methods {@link
      * #getChildNodeNames()} and {@link #getChildNode(String)}, this method is
@@ -199,6 +235,9 @@ public interface NodeState {
      * Compares this node state against the given base state. Any differences
      * are reported by calling the relevant added/changed/deleted methods of
      * the given handler.
+     * <p>
+     * TODO: Define the behavior of this method with regards to
+     * iterability/existence of child nodes.
      *
      * @param base base state
      * @param diff handler of node state differences

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java Thu Apr  4 13:12:22 2013
@@ -130,7 +130,7 @@ public class ReadOnlyBuilder implements 
     @Override
     public ReadOnlyBuilder child(String name) {
         NodeState child = state.getChildNode(name);
-        if (child != null) {
+        if (child.exists()) {
             return new ReadOnlyBuilder(child);
         } else {
             throw unsupported();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java Thu Apr  4 13:12:22 2013
@@ -37,8 +37,10 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
 import static org.apache.jackrabbit.oak.api.Type.LONG;
 
 public class KernelNodeStateTest {
@@ -104,10 +106,10 @@ public class KernelNodeStateTest {
 
     @Test
     public void testGetChildNode() {
-        assertNotNull(state.getChildNode("x"));
-        assertNotNull(state.getChildNode("y"));
-        assertNotNull(state.getChildNode("z"));
-        assertNull(state.getChildNode("a"));
+        assertTrue(state.getChildNode("x").exists());
+        assertTrue(state.getChildNode("y").exists());
+        assertTrue(state.getChildNode("z").exists());
+        assertFalse(state.getChildNode("a").exists());
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java Thu Apr  4 13:12:22 2013
@@ -37,6 +37,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.junit.Before;
 import org.junit.Test;
 
+import static junit.framework.Assert.assertFalse;
 import static org.apache.jackrabbit.oak.api.Type.LONG;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -88,34 +89,34 @@ public class KernelNodeStoreTest {
 
         // Assert changes are present in the builder
         NodeState testState = rootBuilder.getNodeState().getChildNode("test");
-        assertNotNull(testState.getChildNode("newNode"));
-        assertNull(testState.getChildNode("x"));
+        assertTrue(testState.getChildNode("newNode").exists());
+        assertFalse(testState.getChildNode("x").exists());
         assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));
 
         // Assert changes are not yet present in the branch
         testState = branch.getHead().getChildNode("test");
-        assertNull(testState.getChildNode("newNode"));
-        assertNotNull(testState.getChildNode("x"));
+        assertFalse(testState.getChildNode("newNode").exists());
+        assertTrue(testState.getChildNode("x").exists());
 
         branch.setRoot(rootBuilder.getNodeState());
 
         // Assert changes are present in the branch
         testState = branch.getHead().getChildNode("test");
-        assertNotNull(testState.getChildNode("newNode"));
-        assertNull(testState.getChildNode("x"));
+        assertTrue(testState.getChildNode("newNode").exists());
+        assertFalse(testState.getChildNode("x").exists());
         assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));
 
         // Assert changes are not yet present in the trunk
         testState = store.getRoot().getChildNode("test");
-        assertNull(testState.getChildNode("newNode"));
-        assertNotNull(testState.getChildNode("x"));
+        assertFalse(testState.getChildNode("newNode").exists());
+        assertTrue(testState.getChildNode("x").exists());
 
         branch.merge(EmptyHook.INSTANCE);
 
         // Assert changes are present in the trunk
         testState = store.getRoot().getChildNode("test");
-        assertNotNull(testState.getChildNode("newNode"));
-        assertNull(testState.getChildNode("x"));
+        assertTrue(testState.getChildNode("newNode").exists());
+        assertFalse(testState.getChildNode("x").exists());
         assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));
     }
 
@@ -151,9 +152,9 @@ public class KernelNodeStoreTest {
         assertNotNull(before);
         assertNotNull(after);
 
-        assertNull(before.getChildNode("test").getChildNode("newNode"));
-        assertNotNull(after.getChildNode("test").getChildNode("newNode"));
-        assertNull(after.getChildNode("test").getChildNode("a"));
+        assertFalse(before.getChildNode("test").getChildNode("newNode").exists());
+        assertTrue(after.getChildNode("test").getChildNode("newNode").exists());
+        assertFalse(after.getChildNode("test").getChildNode("a").exists());
         assertEquals(42, (long) after.getChildNode("test").getChildNode("newNode").getProperty("n").getValue(LONG));
         assertEquals(newRoot, after);
     }
@@ -184,9 +185,9 @@ public class KernelNodeStoreTest {
         });
 
         NodeState test = store.getRoot().getChildNode("test");
-        assertNotNull(test.getChildNode("newNode"));
-        assertNotNull(test.getChildNode("fromHook"));
-        assertNull(test.getChildNode("a"));
+        assertTrue(test.getChildNode("newNode").exists());
+        assertTrue(test.getChildNode("fromHook").exists());
+        assertFalse(test.getChildNode("a").exists());
         assertEquals(42, (long) test.getChildNode("newNode").getProperty("n").getValue(LONG));
         assertEquals(test, store.getRoot().getChildNode("test"));
     }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java Thu Apr  4 13:12:22 2013
@@ -31,8 +31,10 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
 
 public class LargeKernelNodeStateTest {
 
@@ -67,10 +69,10 @@ public class LargeKernelNodeStateTest {
 
     @Test
     public void testGetChildNode() {
-        assertNotNull(state.getChildNode("x0"));
-        assertNotNull(state.getChildNode("x1"));
-        assertNotNull(state.getChildNode("x" + N));
-        assertNull(state.getChildNode("x" + (N + 1)));
+        assertTrue(state.getChildNode("x0").exists());
+        assertTrue(state.getChildNode("x1").exists());
+        assertTrue(state.getChildNode("x" + N).exists());
+        assertFalse(state.getChildNode("x" + (N + 1)).exists());
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java Thu Apr  4 13:12:22 2013
@@ -281,8 +281,8 @@ public class IndexHookManagerTest {
     private static NodeState checkPathExists(NodeState state, String... verify) {
         NodeState c = state;
         for (String p : verify) {
-            assertTrue(c.hasChildNode(p));
             c = c.getChildNode(p);
+            assertTrue(c.exists());
         }
         return c;
     }

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java Thu Apr  4 13:12:22 2013
@@ -322,12 +322,9 @@ public class LuceneIndex implements Quer
             return; // shortcut
         }
         NodeState system = root.getChildNode(NodeTypeConstants.JCR_SYSTEM);
-        if (system == null) {
-            return;
-        }
         final NodeState types =
                 system.getChildNode(NodeTypeConstants.JCR_NODE_TYPES);
-        if (types == null) {
+        if (!types.exists()) {
             return;
         }
 

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java Thu Apr  4 13:12:22 2013
@@ -38,8 +38,7 @@ public abstract class OakSolrNodeStateCo
      * get the {@link org.apache.jackrabbit.oak.spi.state.NodeState} which contains the properties for the Oak -
      * Solr configuration.
      *
-     * @return a {@link org.apache.jackrabbit.oak.spi.state.NodeState} for the Solr configuration or <code>null</code>
-     *         if such a {@link org.apache.jackrabbit.oak.spi.state.NodeState} doesn't exist.
+     * @return a (possibly non-existent) node state for the Solr configuration
      */
     protected abstract NodeState getConfigurationNodeState();
 
@@ -108,7 +107,7 @@ public abstract class OakSolrNodeStateCo
     protected String getStringValueFor(String propertyName, String defaultValue) {
         String value = null;
         NodeState configurationNodeState = getConfigurationNodeState();
-        if (configurationNodeState != null) {
+        if (configurationNodeState.exists()) {
             PropertyState property = configurationNodeState.getProperty(propertyName);
             if (property != null) {
                 value = property.getValue(Type.STRING);

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfiguration.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfiguration.java Thu Apr  4 13:12:22 2013
@@ -38,9 +38,6 @@ public class UpToDateNodeStateConfigurat
         NodeState currentState = store.getRoot();
         for (String child : path.split("/")) {
             currentState = currentState.getChildNode(child);
-            if (currentState == null) {
-                break;
-            }
         }
         return currentState;
     }

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java (original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java Thu Apr  4 13:12:22 2013
@@ -33,6 +33,7 @@ public class DefaultOakSolrProviderTest 
     @Test
     public void testSolrServerInitializationWithoutConfigurationFiles() throws Exception {
         NodeState nodeState = mock(NodeState.class);
+        when(nodeState.exists()).thenReturn(true);
         when(nodeState.getProperty(OakSolrNodeStateConfiguration.Properties.CORE_NAME)).
                 thenReturn(PropertyValues.create(PropertyValues.newString("oak")));
         when(nodeState.getProperty(OakSolrNodeStateConfiguration.Properties.SOLRHOME_PATH)).

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java?rev=1464516&r1=1464515&r2=1464516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java (original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java Thu Apr  4 13:12:22 2013
@@ -9,6 +9,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 
 /**
@@ -46,6 +47,6 @@ public class UpToDateNodeStateConfigurat
     public void testNodeStateNotFound() throws Exception {
         String path = "some/path/to/somewhere/unknown";
         UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store, path);
-        assertNull(upToDateNodeStateConfiguration.getConfigurationNodeState());
+        assertFalse(upToDateNodeStateConfiguration.getConfigurationNodeState().exists());
     }
 }



Mime
View raw message