jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r890401 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Date Mon, 14 Dec 2009 16:49:27 GMT
Author: jukka
Date: Mon Dec 14 16:49:27 2009
New Revision: 890401

URL: http://svn.apache.org/viewvc?rev=890401&view=rev
Log:
JCR-2298: NPE in EventStateCollection

Log an error and skip the REMOVE event when the old parent of a moved node is no longer available.
This is not ideal, but definitely better than the current behaviour of throwing a NullPointerException.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?rev=890401&r1=890400&r2=890401&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Mon Dec 14 16:49:27 2009
@@ -193,6 +193,7 @@
                     NodeId newParentId = n.getParentId();
                     if (newParentId != null && !oldParentId.equals(newParentId) &&
                             !n.isShareable()) {
+                        Path oldPath = getZombiePath(n.getNodeId(), hmgr);
 
                         // node moved
                         // generate node removed & node added event
@@ -204,20 +205,29 @@
                             // shared item state manager
                             oldParent = (NodeState) stateMgr.getItemState(oldParentId);
                         }
-
-                        NodeTypeImpl oldParentNodeType = getNodeType(oldParent, session);
-                        Set<Name> mixins = oldParent.getMixinTypeNames();
-                        Path newPath = getPath(n.getNodeId(), hmgr);
-                        Path oldPath = getZombiePath(n.getNodeId(), hmgr);
-                        events.add(EventState.childNodeRemoved(oldParentId,
-                                getParent(oldPath), n.getNodeId(),
-                                oldPath.getNameElement(),
-                                oldParentNodeType.getQName(),
-                                mixins, session));
+                        if (oldParent != null) {
+                            NodeTypeImpl oldParentNodeType = getNodeType(oldParent, session);
+                            events.add(EventState.childNodeRemoved(oldParentId,
+                                    getParent(oldPath), n.getNodeId(),
+                                    oldPath.getNameElement(),
+                                    oldParentNodeType.getQName(),
+                                    oldParent.getMixinTypeNames(), session));
+                        } else {
+                            // JCR-2298: In some cases the old parent node
+                            // state is no longer available anywhere. Log an
+                            // error since in this case we can't generate the
+                            // correct REMOVE event.
+                            log.error(
+                                    "The old parent (node id " + oldParentId
+                                    + ") of a moved node (old path "
+                                    + oldPath + ") is no longer available."
+                                    + " No REMOVE event generated!");
+                        }
 
                         NodeState newParent = (NodeState) changes.get(newParentId);
                         NodeTypeImpl newParentNodeType = getNodeType(newParent, session);
-                        mixins = newParent.getMixinTypeNames();
+                        Set<Name> mixins = newParent.getMixinTypeNames();
+                        Path newPath = getPath(n.getNodeId(), hmgr);
                         events.add(EventState.childNodeAdded(newParentId,
                                 getParent(newPath), n.getNodeId(),
                                 newPath.getNameElement(),



Mime
View raw message