Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-32516

Avoid DocumentNotFoundException in listener 'checkedInCommentListener'

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2021.0, 2023.0
    • Fix Version/s: 2021.x, 2023.13
    • Component/s: Comments
    • Release Notes Summary:
      Fixed DocumentNotFoundException in "checkedInCommentListener".
    • Backlog priority:
      500

      Description

      It can happen that the document that listener checkedInCommentListener processes has been deleted.

      org.nuxeo.ecm.core.api.NuxeoException: Work failed after 2 retries, class=class org.nuxeo.ecm.core.event.impl.AsyncEventExecutor$ListenerWork id=11084563590708.1167959855 category=checkedInCommentListener title=Listener checkedInCommentListener [documentCheckedIn/63290d9f-f114-44ae-902d-0b470d0485ac]
        at org.nuxeo.ecm.core.work.AbstractWork.workFailed(AbstractWork.java:470)
        at org.nuxeo.ecm.core.work.AbstractWork.run(AbstractWork.java:400)
        at org.nuxeo.ecm.core.work.WorkHolder.run(WorkHolder.java:57)
        at org.nuxeo.ecm.core.work.WorkComputation.processRecord(WorkComputation.java:105)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.lambda$processRecordWithRetry$10(ComputationRunner.java:514)
        at net.jodah.failsafe.Functions$10.call(Functions.java:252)
        at net.jodah.failsafe.SyncFailsafe.call(SyncFailsafe.java:145)
        at net.jodah.failsafe.SyncFailsafe.run(SyncFailsafe.java:81)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.processRecordWithRetry(ComputationRunner.java:514)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.processRecordWithTracing(ComputationRunner.java:465)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.processRecord(ComputationRunner.java:457)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.processLoop(ComputationRunner.java:315)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.runOnce(ComputationRunner.java:259)
        at org.nuxeo.lib.stream.computation.log.ComputationRunner.run(ComputationRunner.java:226)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
       Caused by: org.nuxeo.ecm.core.api.DocumentNotFoundException: 1525adec-6991-4a0e-803d-c49798501fff
        at org.nuxeo.ecm.core.storage.dbs.DBSSession.getDocumentByUUID(DBSSession.java:407)
        at org.nuxeo.ecm.core.api.AbstractSession.resolveReference(AbstractSession.java:385)
        at org.nuxeo.ecm.core.api.AbstractSession.hasChild(AbstractSession.java:945)
        at org.nuxeo.ecm.platform.comment.listener.CheckedInCommentListener.handleEvent(CheckedInCommentListener.java:65)
        at org.nuxeo.ecm.platform.comment.listener.CheckedInCommentListener.handleEvent(CheckedInCommentListener.java:56)
        at org.nuxeo.ecm.core.event.impl.AsyncEventExecutor$ListenerWork.work(AsyncEventExecutor.java:209)
        at org.nuxeo.ecm.core.work.AbstractWork.runWorkWithTransaction(AbstractWork.java:524)
        at org.nuxeo.ecm.core.work.AbstractWork.run(AbstractWork.java:387)
       ... 17 more
       Suppressed: org.nuxeo.ecm.core.api.DocumentNotFoundException: 1525adec-6991-4a0e-803d-c49798501fff
        ... 25 more
       Suppressed: org.nuxeo.ecm.core.api.DocumentNotFoundException: 1525adec-6991-4a0e-803d-c49798501fff
        ... 25 more
       ", "className": "impl.AsyncEventExecutor", "message": "Failed to execute async event default on listener checkedInCommentListener
      

      In order to avoid a DocumentNotFoundException exception, we should check the existence of the document before accessing it.

      diff --git a/modules/platform/nuxeo-platform-comment/nuxeo-platform-comment/src/main/java/org/nuxeo/ecm/platform/comment/listener/CheckedInCommentListener.java b/modules/platform/nuxeo-platform-comment/nuxeo-platform-comment/src/main/java/org/nuxeo/ecm/platform/comment/listener/CheckedInCommentListener.java
      index 08c050772d0..01a5dc4070a 100644
      --- a/modules/platform/nuxeo-platform-comment/nuxeo-platform-comment/src/main/java/org/nuxeo/ecm/platform/comment/listener/CheckedInCommentListener.java
      +++ b/modules/platform/nuxeo-platform-comment/nuxeo-platform-comment/src/main/java/org/nuxeo/ecm/platform/comment/listener/CheckedInCommentListener.java
      @@ -27,6 +27,8 @@ import static org.nuxeo.ecm.platform.comment.impl.AbstractCommentManager.COMMENT
       import java.util.ArrayList;
       import java.util.Arrays;
       
      +import org.apache.logging.log4j.LogManager;
      +import org.apache.logging.log4j.Logger;
       import org.nuxeo.ecm.core.api.CoreSession;
       import org.nuxeo.ecm.core.api.DocumentModel;
       import org.nuxeo.ecm.core.api.DocumentModelList;
      @@ -44,6 +46,8 @@ import org.nuxeo.ecm.core.event.PostCommitFilteringEventListener;
        */
       public class CheckedInCommentListener implements PostCommitFilteringEventListener {
       
      +    private static final Logger log = LogManager.getLogger(CheckedInCommentListener.class);
      +
           @Override
           public boolean acceptEvent(Event event) {
               return DOCUMENT_CHECKEDIN.equals(event.getName());
      @@ -62,9 +66,13 @@ public class CheckedInCommentListener implements PostCommitFilteringEventListene
               EventContext ctx = event.getContext();
               CoreSession session = ctx.getCoreSession();
               DocumentRef versionRef = (DocumentRef) ctx.getProperty("checkedInVersionRef");
      -        if (versionRef != null && session.hasChild(versionRef, COMMENTS_DIRECTORY)) {
      -            DocumentModel comments = session.getChild(versionRef, COMMENTS_DIRECTORY);
      -            updateCommentProperties(session, comments.getId(), versionRef.reference().toString());
      +        if (session.exists(versionRef)) {
      +            if (versionRef != null && session.hasChild(versionRef, COMMENTS_DIRECTORY)) {
      +                DocumentModel comments = session.getChild(versionRef, COMMENTS_DIRECTORY);
      +                updateCommentProperties(session, comments.getId(), versionRef.reference().toString());
      +            }
      +        } else {
      +            log.warn("Document {} does not exist, SKIPPED.", versionRef);
               }
           }
       
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: