Uploaded image for project: 'Jackrabbit Oak'
  1. Jackrabbit Oak
  2. OAK-8057

ItemExistsException in ImporterImpl despite COLLISION_REPLACE_EXISTING



    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.8
    • Fix Version/s: None
    • Component/s: jcr
    • Labels:
    • Environment:

      Sling Launchpad 11


      I tried exporting a document view XML with javax.jcr.Session#exportDocumentView of a node and re-importing it using javax.jcr.Session#getImportContentHandler with ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING into the node's parent, which should IMHO always work and not change that node, right? Unfortunately that throws an ItemExistsException "Node with the same UUID exists..." in some cases, that shouldn't be thrown to my understanding. I ran the following code:

      ByteArrayOutputStream sout = new ByteArrayOutputStream();
      session.exportDocumentView(node.getPath(), sout, false, false);
      LOG.info("Document View:\n{}", sout.toString("UTF-8"));
      XMLReader xmlreader = saxParserFactory.newSAXParser().getXMLReader();
      xmlreader.setContentHandler(session.getImportContentHandler(node.getParent().getPath(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING));
      xmlreader.parse(new InputSource(new ByteArrayInputStream(sout.toByteArray())));

      The simplest example where this throws an unwarranted ItemExistsException is when you run this on a node of jcr:primaryType nt:file . The problem lies in the condition at lines 419 / 420 of ImporterImpl.java : IdentifierManager.getIdentifier(existing) always returns something - if there is no jcr:uuid it returns a path. But id is null here (the node has no jcr:uuid in the imported XML), so the condition always fails if that branch is reached. Perhaps that comparison should use the actual jcr:uuid of 'existing' ?

      By the way: I suggest to apply De Morgans law to the condition in line 420 to make it more readable. That'd be

      if (!existingIdentifier.equals(id)
              || (uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                  && uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)))

      that is, if it is really correct.
      I tried this with version 1.8.8 in the Sling Launchpad, but I suppose this problem persists with 1.9.13 since that code is unchanged.

      Thanks so much!

      PS: I noticed the process of exporting and re-importing DocumentView XML also changes the datatype of boolean attributes to String. But I'm not sure whether this is a bug or a feature.




            • Assignee:
              hanspeterstoerr Hans-Peter Stoerr
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: