protogenes commented on PR #962:
URL: https://github.com/apache/jackrabbit-oak/pull/962#issuecomment-5726818166

   Despite this being an old, merged topic, here still seems like the best 
place for discussion.
   I encountered a corner case that works with `ClassicMove` but not with 
`NeoMove`:
   If you indirectly move a tree to a path below its original location `/x -> 
/x/a`, all `Tree` references to descendants become invalid.
   
   ```java
   Tree xx = root.getTree("/x/xx");
   root.move("/x", "/a");
   // workaround: xx.getPath();
   root.getTree("/").addChild("x");
   root.move("/a", "/x/a");
   assertEquals("/x/a/xx", xx.getPath()); // fails as path is "/x/a/a/xx" with 
NeoMove
   ```
   
   Looking at `org.apache.jackrabbit.oak.core.MutableTree#applyPendingMoves` 
the moves are applied multiple times to a path:
   1. moves are applied to the parent tree
   2. `NeoMove.apply` constructs the most recent path and then
   3. applies the same moves again, if the paths overlap as above
   
   The easy solution is to store the path instead of constructing it from the 
parent which was already rewritten.
   The stored path matches the state of pendingMoves at all times and can be 
rewritten directly.
   
   Alternatively one could restore the path matching the pendingMoves by 
reverse-rewriting the parent path, requiring a weak back reference in `NeoMove` 
and effectively doubling the rewrite operations.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to