Skip to content

Commit

Permalink
Merge pull request #975 from mreutegg/OAK-9660-1
Browse files Browse the repository at this point in the history
OAK-9660: NullPointerException When Moving Transient node
  • Loading branch information
mreutegg committed Jun 12, 2023
2 parents a520e5d + 9186a65 commit 22e72d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.oak.NodeStoreFixtures;
import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.Parameterized;

import static java.util.Collections.singleton;
import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.MEMORY_NS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TransientMoveTest extends AbstractRepositoryTest {
Expand All @@ -45,7 +45,6 @@ public static Collection<Object[]> memoryFixture() {
return NodeStoreFixtures.asJunitParameters(singleton(MEMORY_NS));
}

@Ignore("OAK-9660")
@Test
public void transientMove() throws Exception {
// setup
Expand Down Expand Up @@ -91,14 +90,16 @@ public void transientMove() throws Exception {
// What we really want to do is copy the child, but creating a new node with the same name is sufficient.
// In the real world, this would have content on it, so all the properties and children would be copied - for testing it doesn't matter.
// JcrUtil.copy(child, parent, "child", false);
parent.addNode(child.getName(), child.getPrimaryNodeType().getName());
Node c = parent.addNode(child.getName(), child.getPrimaryNodeType().getName());

assertTrue(session.hasPendingChanges()); // None of these changes have been persisted yet. This is to verify that no auto-saves have occurred.

// Now, we need to actually process the child, so we need to move it so a new node can be created in its place, with the name "child".
session.move("/var/oak-bug/test/parent/child", "/var/oak-bug/test/parent/tmp-4321"); // NPE On this Call.

session.save();

assertEquals("/var/oak-bug/test/parent/tmp-4321", c.getPath());
} finally {
session.logout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,13 @@ private static String getSourcePathAnnotation(MemoryNodeBuilder builder) {
PropertyState head = builder.getNodeState().getProperty(MoveDetector.SOURCE_PATH);
if (Objects.equal(base, head)) {
// Both null: no source path annotation
// Both non null but equals: source path annotation is from a previous commit
// Both non-null but equals: source path annotation is from a previous commit
return null;
} else {
return head.getValue(Type.STRING);
// OAK-9660: base may have a source path and head does not.
// happens when this node had a source path and was transiently
// removed and added again (without source path).
return head != null ? head.getValue(Type.STRING) : null;
}
}

Expand Down

0 comments on commit 22e72d6

Please sign in to comment.