jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1404014 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
Date Wed, 31 Oct 2012 07:58:32 GMT
Author: mreutegg
Date: Wed Oct 31 07:58:32 2012
New Revision: 1404014

URL: http://svn.apache.org/viewvc?rev=1404014&view=rev
Log:
OAK-395: Inconsistency in Node#setProperty in case of null value
- return a Property instance at the location where the property was removed
- updated tests in CRUDTest accordingly

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=1404014&r1=1404013&r2=1404014&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
Wed Oct 31 07:58:32 2012
@@ -1450,13 +1450,17 @@ public class NodeImpl extends ItemImpl<N
         return sessionDelegate.perform(new SessionOperation<Property>() {
             @Override
             public Property perform() throws RepositoryException {
+                String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
                 if (value == null) {
-                    Property property = getProperty(jcrName);
-                    property.remove();
-                    return property;
+                    if (hasProperty(jcrName)) {
+                        Property property = getProperty(jcrName);
+                        property.remove();
+                        return property;
+                    } else {
+                        return new PropertyImpl(new PropertyDelegate(
+                                sessionDelegate, dlg.getLocation().getChild(oakName)));
+                    }
                 } else {
-                    String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
-
                     PropertyDefinition definition;
                     if (hasProperty(jcrName)) {
                         definition = getProperty(jcrName).getDefinition();
@@ -1485,13 +1489,17 @@ public class NodeImpl extends ItemImpl<N
         return sessionDelegate.perform(new SessionOperation<Property>() {
             @Override
             public Property perform() throws RepositoryException {
+                String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
                 if (values == null) {
-                    Property p = getProperty(jcrName);
-                    p.remove();
-                    return p;
+                    if (hasProperty(jcrName)) {
+                        Property property = getProperty(jcrName);
+                        property.remove();
+                        return property;
+                    } else {
+                        return new PropertyImpl(new PropertyDelegate(
+                                sessionDelegate, dlg.getLocation().getChild(oakName)));
+                    }
                 } else {
-                    String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
-
                     PropertyDefinition definition;
                     if (hasProperty(jcrName)) {
                         definition = getProperty(jcrName).getDefinition();

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=1404014&r1=1404013&r2=1404014&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
Wed Oct 31 07:58:32 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
@@ -85,11 +86,13 @@ public class CRUDTest extends AbstractRe
     public void testRemoveMissingProperty() throws RepositoryException {
         Session session = getAdminSession();
         Node root = session.getRootNode();
+        Property p = root.setProperty("missing", (String) null);
+        assertNotNull(p);
         try {
-            root.setProperty("missing", (String) null);
-            fail("removing a missing property should fail");
-        } catch (PathNotFoundException e) {
-            // success
+            p.getValue();
+            fail("must throw InvalidItemStateException");
+        } catch (InvalidItemStateException e) {
+            // expected
         }
     }
 
@@ -97,11 +100,13 @@ public class CRUDTest extends AbstractRe
     public void testRemoveMissingMVProperty() throws RepositoryException {
         Session session = getAdminSession();
         Node root = session.getRootNode();
+        Property p = root.setProperty("missing", (String[]) null);
+        assertNotNull(p);
         try {
-            root.setProperty("missing", (String[]) null);
-            fail("removing a missing property should fail");
-        } catch (PathNotFoundException e) {
-            // success
+            p.getValues();
+            fail("must throw InvalidItemStateException");
+        } catch (InvalidItemStateException e) {
+            // expected
         }
     }
 



Mime
View raw message