Index: src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (revision 899132) +++ src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (working copy) @@ -572,6 +572,8 @@ checkReferentialIntegrity(); } + checkAddedChildNodes(); + /** * prepare the events. this needs to be after the referential * integrity check, since another transaction could have modified @@ -957,6 +959,40 @@ } /** + * Verify the added child nodes of the added or modified states exist. + * If they don't exist, most likely the problem is that the same session + * is used concurrently. + */ + private void checkAddedChildNodes() throws ItemStateException { + for (Iterator iter = local.addedStates(); iter.hasNext();) { + checkAddedChildNode((ItemState) iter.next()); + } + for (Iterator iter = local.modifiedStates(); iter.hasNext();) { + checkAddedChildNode((ItemState) iter.next()); + } + } + + private void checkAddedChildNode(ItemState state) throws ItemStateException { + if (state.isNode()) { + NodeState node = (NodeState) state; + + for (Iterator iter = node.getAddedChildNodeEntries().iterator(); + iter.hasNext();) { + ChildNodeEntry cne = + (ChildNodeEntry) iter.next(); + NodeId id = cne.getId(); + if (local.get(id) == null) { + if (!cache.isCached(id) && !persistMgr.exists(id)) { + String msg = "Trying to add a non-existing child node: " + id; + log.debug(msg); + throw new ItemStateException(msg); + } + } + } + } + } + + /** * Verifies that *