jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1342286 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 24 May 2012 14:49:20 GMT
Author: mduerig
Date: Thu May 24 14:49:19 2012
New Revision: 1342286

URL: http://svn.apache.org/viewvc?rev=1342286&view=rev
Log:
OAK-37: Use nullability annotation to enforce/document API contract
- add nullability annotations to Tree

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java?rev=1342286&r1=1342285&r2=1342286&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java Thu
May 24 14:49:19 2012
@@ -18,9 +18,9 @@
  */
 package org.apache.jackrabbit.oak.api;
 
-import java.util.List;
-
 import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import java.util.List;
 
 /**
  * A tree instance represents a snapshot of the {@code ContentRepository}
@@ -73,16 +73,19 @@ public interface Tree {
     /**
      * @return  the name of this {@code Tree} instance.
      */
+    @Nonnull
     String getName();
 
     /**
      * @return  path of this {@code Tree} instance relative to its {@link Root}.
      */
+    @Nonnull
     String getPath();
 
     /**
-     * @return  the parent of this {@code Tree} instance.
+     * @return  the parent of this {@code Tree} instance or {@code null} for the root.
      */
+    @CheckForNull
     Tree getParent();
 
     /**
@@ -100,6 +103,7 @@ public interface Tree {
      * @return  the status of the property state with the given {@code name}
      *          or {@code null} in no such property state exists.
      */
+    @CheckForNull
     Status getPropertyStatus(String name);
 
     /**
@@ -123,6 +127,7 @@ public interface Tree {
      * the returned iterable.
      * @return  An {@code Iterable} for all property states
      */
+    @Nonnull
     Iterable<? extends PropertyState> getProperties();
 
     /**
@@ -131,6 +136,7 @@ public interface Tree {
      * @return  the child with the given {@code name} or {@code null} if no such child
      * exists.
      */
+    @CheckForNull
     Tree getChild(String name);
 
     /**
@@ -139,6 +145,7 @@ public interface Tree {
      * @return  the status of the child with the given {@code name} or {@code null} in
      *          no such child exists.
      */
+    @CheckForNull
     Status getChildStatus(String name);
 
     /**
@@ -162,6 +169,7 @@ public interface Tree {
      * visible to iterators obtained from the returned iterable.
      * @return  An {@code Iterable} for all children
      */
+    @Nonnull
     Iterable<Tree> getChildren();
 
     /**
@@ -171,6 +179,7 @@ public interface Tree {
      * @param name name of the child
      * @return the {@code Tree} instance of the child with the given {@code name}.
      */
+    @Nonnull
     Tree addChild(String name);
 
     /**
@@ -187,6 +196,7 @@ public interface Tree {
      * @param value The value of this property
      * @return the affected property state
      */
+    @Nonnull
     PropertyState setProperty(String name, CoreValue value);
 
     /**
@@ -196,6 +206,7 @@ public interface Tree {
      * @param values The value of this property
      * @return the affected property state
      */
+    @Nonnull
     PropertyState setProperty(String name, List<CoreValue> values);
 
     /**

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=1342286&r1=1342285&r2=1342286&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 May 24 14:49:19 2012
@@ -56,6 +56,9 @@ public class TreeImpl implements Tree, P
     private final Children children = new Children();
 
     private TreeImpl(RootImpl root, TreeImpl parent, String name) {
+        assert root != null;
+        assert name != null;
+
         this.root = root;
         this.parent = parent;
         this.name = name;
@@ -268,7 +271,9 @@ public class TreeImpl implements Tree, P
             updateParentState(builder.getNodeState());
         }
 
-        return getChild(name);
+        TreeImpl child = getChild(name);
+        assert child != null;
+        return child;
     }
 
     @Override
@@ -290,7 +295,9 @@ public class TreeImpl implements Tree, P
         NodeStateBuilder builder = getNodeStateBuilder();
         builder.setProperty(name, value);
         updateParentState(builder.getNodeState());
-        return getProperty(name);
+        PropertyState property = getProperty(name);
+        assert property != null;
+        return property;
     }
 
     @Override
@@ -298,7 +305,9 @@ public class TreeImpl implements Tree, P
         NodeStateBuilder builder = getNodeStateBuilder();
         builder.setProperty(name, values);
         updateParentState(builder.getNodeState());
-        return getProperty(name);
+        PropertyState property = getProperty(name);
+        assert property != null;
+        return property;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1342286&r1=1342285&r2=1342286&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Thu May 24 14:49:19 2012
@@ -79,7 +79,11 @@ public class NodeDelegate extends ItemDe
             return Status.EXISTING;  // FIXME: return correct status for root
         }
         else {
-            return parent.getChildStatus(getName());
+            Status childStatus = parent.getChildStatus(getName());
+            if (childStatus == null) {
+                throw new InvalidItemStateException("Node is stale");
+            }
+            return childStatus;
         }
     }
 
@@ -209,10 +213,13 @@ public class NodeDelegate extends ItemDe
     }
 
     /**
-     * Remove the node
+     * Remove the node if not root. Does nothing otherwise
      */
     public void remove() throws InvalidItemStateException {
-        getParentTree().removeChild(getName());
+        Tree parentTree = getParentTree();
+        if (parentTree != null) {
+            parentTree.removeChild(getName());
+        }
     }
 
     // -----------------------------------------------------------< private >---
@@ -228,6 +235,7 @@ public class NodeDelegate extends ItemDe
         return tree;
     }
 
+    @CheckForNull
     private Tree getParentTree() throws InvalidItemStateException {
         return getTree().getParent();
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1342286&r1=1342285&r2=1342286&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Thu May 24 14:49:19 2012
@@ -138,6 +138,10 @@ public class NodeImpl extends ItemImpl i
     @Override
     public void remove() throws RepositoryException {
         checkStatus();
+        if (dlg.isRoot()) {
+                throw new RepositoryException("Cannot remove the root node");
+        }
+
         dlg.remove();
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1342286&r1=1342285&r2=1342286&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Thu May 24 14:49:19 2012
@@ -81,7 +81,12 @@ public class PropertyDelegate extends It
 
     @Override
     public Status getStatus() throws InvalidItemStateException {
-        return getParentTree().getPropertyStatus(getName());
+        Status propertyStatus = getParentTree().getPropertyStatus(getName());
+        if (propertyStatus == null) {
+            throw new InvalidItemStateException("Property is stale");
+        }
+
+        return propertyStatus;
     }
 
     @Override



Mime
View raw message