You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Hans-Peter Stoerr (JIRA)" <ji...@apache.org> on 2019/02/18 15:58:00 UTC

[jira] [Updated] (OAK-8057) ItemExistsException in ImporterImpl despite COLLISION_REPLACE_EXISTING

     [ https://issues.apache.org/jira/browse/OAK-8057?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hans-Peter Stoerr updated OAK-8057:
-----------------------------------
    Description: 
I tried exporting a document view XML with javax.jcr.Session#exportDocumentView and re-importing it using javax.jcr.Session#getImportContentHandler with ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING into the same 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:
{code:java}
            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())));{code}
 
 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|https://github.com/apache/jackrabbit-oak/blob/jackrabbit-oak-1.9.13/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/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
{code:java}
    !existingIdentifier.equals(id)
                             || (uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                             && uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))){code}
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!

  was:
I tried exporting a document view XML with javax.jcr.Session#exportDocumentView and re-importing it using javax.jcr.Session#getImportContentHandler with ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING into the same 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|https://github.com/apache/jackrabbit-oak/blob/jackrabbit-oak-1.9.13/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/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


    !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!


> ItemExistsException in ImporterImpl despite COLLISION_REPLACE_EXISTING
> ----------------------------------------------------------------------
>
>                 Key: OAK-8057
>                 URL: https://issues.apache.org/jira/browse/OAK-8057
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: jcr
>    Affects Versions: 1.8.8
>         Environment: Sling Launchpad 11
>            Reporter: Hans-Peter Stoerr
>            Priority: Minor
>
> I tried exporting a document view XML with javax.jcr.Session#exportDocumentView and re-importing it using javax.jcr.Session#getImportContentHandler with ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING into the same 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:
> {code:java}
>             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())));{code}
>  
>  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|https://github.com/apache/jackrabbit-oak/blob/jackrabbit-oak-1.9.13/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/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
> {code:java}
>     !existingIdentifier.equals(id)
>                              || (uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
>                              && uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))){code}
> 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!



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)