Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7BF1899C0 for ; Thu, 24 May 2012 14:49:45 +0000 (UTC) Received: (qmail 78746 invoked by uid 500); 24 May 2012 14:49:45 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 78717 invoked by uid 500); 24 May 2012 14:49:45 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-commits@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 78708 invoked by uid 99); 24 May 2012 14:49:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 May 2012 14:49:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 May 2012 14:49:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 645DE238896F; Thu, 24 May 2012 14:49:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: oak-commits@jackrabbit.apache.org From: mduerig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120524144920.645DE238896F@eris.apache.org> 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 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 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 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