Author: angela
Date: Thu Oct 25 10:36:21 2012
New Revision: 1402087

URL: http://svn.apache.org/viewvc?rev=1402087&view=rev
Log:
OAK-395 : Inconsistency in Node#setProperty in case of null value

Modified:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java

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=1402087&r1=1402086&r2=1402087&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 Oct 25 10:36:21 2012
@@ -302,19 +302,20 @@ public class NodeImpl extends ItemImpl<N
      * @see Node#setProperty(String, javax.jcr.Value, int)
      */
     @Override
-    @CheckForNull
+    @Nonnull
     public Property setProperty(final String jcrName, final Value value, final 
int type)
             throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<PropertyImpl>() {
+        return sessionDelegate.perform(new SessionOperation<Property>() {
             @Override
-            public PropertyImpl perform() throws RepositoryException {
-                String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
+            public Property perform() throws RepositoryException {
                 if (value == null) {
-                    dlg.removeProperty(oakName);
-                    return null;
+                    Property property = getProperty(jcrName);
+                    property.remove();
+                    return property;
                 } else {
+                    String oakName = 
sessionDelegate.getOakPathOrThrow(jcrName);
                     int targetType = getTargetType(value, type);
                     Value targetValue =
                             ValueHelper.convert(value, targetType, 
getValueFactory());

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java?rev=1402087&r1=1402086&r2=1402087&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
 Thu Oct 25 10:36:21 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -24,7 +25,9 @@ import javax.jcr.Session;
 import org.junit.Test;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
 
 public class CRUDTest extends AbstractRepositoryTest {
 
@@ -55,10 +58,51 @@ public class CRUDTest extends AbstractRe
     }
 
     @Test
+    public void testRemoveBySetProperty() throws RepositoryException {
+        Session session = getAdminSession();
+        Node root = session.getRootNode();
+        try {
+            root.setProperty("test", "abc");
+            assertNotNull(root.setProperty("test", (String) null));
+        } catch (PathNotFoundException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testRemoveBySetMVProperty() throws RepositoryException {
+        Session session = getAdminSession();
+        Node root = session.getRootNode();
+        try {
+            root.setProperty("test", new String[] {"abc", "def"});
+            assertNotNull(root.setProperty("test", (String[]) null));
+        } catch (PathNotFoundException e) {
+            // success
+        }
+    }
+
+    @Test
     public void testRemoveMissingProperty() throws RepositoryException {
         Session session = getAdminSession();
         Node root = session.getRootNode();
-        root.setProperty("missing", (String) null);
+        try {
+            root.setProperty("missing", (String) null);
+            fail("removing a missing property should fail");
+        } catch (PathNotFoundException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testRemoveMissingMVProperty() throws RepositoryException {
+        Session session = getAdminSession();
+        Node root = session.getRootNode();
+        try {
+            root.setProperty("missing", (String[]) null);
+            fail("removing a missing property should fail");
+        } catch (PathNotFoundException e) {
+            // success
+        }
     }
 
     @Test


Reply via email to