You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by kw...@apache.org on 2021/09/18 14:49:29 UTC

[jackrabbit-oak] branch trunk updated: OAK-9541 fix exception message when trying to overwrite existing node (#343)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new efd214f  OAK-9541 fix exception message when trying to overwrite existing node (#343)
efd214f is described below

commit efd214f583f08cea1a922f7495d36bd9e5b8f3ce
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Sat Sep 18 16:49:23 2021 +0200

    OAK-9541 fix exception message when trying to overwrite existing node (#343)
    
    with different UUID
---
 .../jackrabbit/oak/jcr/xml/ImporterImpl.java       |  5 +--
 .../apache/jackrabbit/oak/jcr/xml/ImportTest.java  | 46 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
index 9c6888b..5049fbb 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
@@ -417,14 +417,13 @@ public class ImporterImpl implements Importer {
                     // this node has already been auto-created, no need to create it
                     tree = existing;
                 } else {
-                    // edge case: colliding node does have same uuid
+                    // edge case: colliding node with same uuid should not trigger an exception for certain uuidBehaviors
                     // (see http://issues.apache.org/jira/browse/JCR-1128)
                     String existingIdentifier = IdentifierManager.getIdentifier(existing);
                     if (!(existingIdentifier.equals(id)
                             && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                             || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
-                        throw new ItemExistsException(
-                                "Node with the same UUID exists:" + existing);
+                        throw new ItemExistsException("Node with name " + nodeName + " already exists at this path.");
                     }
                     // fall through
                 }
diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/xml/ImportTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/xml/ImportTest.java
index 5a0dd4e..631f3cb 100644
--- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/xml/ImportTest.java
+++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/xml/ImportTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.jcr.xml;
 
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThrows;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -30,9 +33,9 @@ import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
-import static org.junit.Assert.assertNotEquals;
 
 public class ImportTest extends AbstractJCRTest {
 
@@ -55,6 +58,10 @@ public class ImportTest extends AbstractJCRTest {
     }
 
     private InputStream getImportStream() throws RepositoryException, IOException {
+        return getImportStream(path);
+    }
+
+    private InputStream getImportStream(String path) throws RepositoryException, IOException {
         OutputStream out = new ByteArrayOutputStream();
         superuser.exportSystemView(path, out, true, false);
         return new ByteArrayInputStream(out.toString().getBytes());
@@ -77,6 +84,43 @@ public class ImportTest extends AbstractJCRTest {
     }
 
     /**
+     * @see <a href="https://issues.apache.org/jira/browse/OAK-9541">OAK-9541</a>
+     * @throws Exception
+     *
+     */
+    public void testOverwriteDifferentUUIDSamePath() throws Exception {
+        // export of node1/node1 (nt:folder in nt:folder, does not allow sns)
+        superuser.removeItem(path);
+        Node node = testRootNode.addNode(nodeName1, JcrConstants.NT_FOLDER);
+        Node subNode = node.addNode(nodeName1, JcrConstants.NT_FOLDER);
+        subNode.addMixin(mixReferenceable);
+        superuser.save();
+        uuid = subNode.getIdentifier();
+        InputStream sysViewInputStream = getImportStream(subNode.getPath());
+        sysViewInputStream.mark(Integer.MAX_VALUE);
+
+        // replace uuid of node1/node1
+        superuser.removeItem(subNode.getPath());
+        subNode = node.addNode(nodeName1, JcrConstants.NT_FOLDER);
+        subNode.addMixin(mixReferenceable);
+        assertNotEquals(uuid, subNode.getIdentifier());
+        superuser.save();
+
+        // reimport node1/node1 must throw exception
+        ItemExistsException e = assertThrows(ItemExistsException.class, () -> { superuser.importXML(node.getPath(), sysViewInputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING); });
+        assertFalse(e.getMessage().contains("UUID"));
+        sysViewInputStream.reset();
+        e = assertThrows(ItemExistsException.class, () -> { superuser.importXML(node.getPath(), sysViewInputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); });
+        assertFalse(e.getMessage().contains("UUID"));
+        sysViewInputStream.reset();
+        e = assertThrows(ItemExistsException.class, () -> { superuser.importXML(node.getPath(), sysViewInputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW); });
+        assertFalse(e.getMessage().contains("UUID"));
+        sysViewInputStream.reset();
+        e = assertThrows(ItemExistsException.class, () -> { superuser.importXML(node.getPath(), sysViewInputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); });
+        assertFalse(e.getMessage().contains("UUID"));
+    }
+
+    /**
      * @see <a href="https://issues.apache.org/jira/browse/OAK-2246">OAK-2246</a>
      */
     public void testTransientReplaceUUID() throws Exception {