Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (revision 1403722) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (working copy) @@ -1450,13 +1450,17 @@ return sessionDelegate.perform(new SessionOperation() { @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 @@ return sessionDelegate.perform(new SessionOperation() { @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(); Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java =================================================================== --- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java (revision 1403722) +++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java (working copy) @@ -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 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 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 } }