Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-5991

Maybe race condition in loadDocumentArchive

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0 M2
    • Fix Version/s: 3.0 M3
    • Component/s: {Unused} Core
    • Labels:
      None
    • keywords:
      patch, bugfixingday
    • Difficulty:
      Trivial
    • Similar issues:

      Description

      I noticed this potential race condition:

              if (getDocumentArchive() != null) {
                  return getDocumentArchive();
              }
      

      The soft reference may theoretically be garbage collected between the calls. I'm not sure that this could happen in practice, as the document archive must have been loaded using a different context than the current one. But if getDocumentArchive is called only once, the race condition obviously cannot occur:

      Index: xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
      ===================================================================
      --- xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(revision 34604)
      +++ xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(working copy)
      @@ -1740,14 +1740,15 @@
            */
           public XWikiDocumentArchive loadDocumentArchive()
           {
      -        if (getDocumentArchive() != null) {
      -            return getDocumentArchive();
      +        XWikiDocumentArchive arch = getDocumentArchive();
      +        if (arch != null) {
      +            return arch;
               }
       
               XWikiContext xcontext = getXWikiContext();
       
               try {
      -            XWikiDocumentArchive arch = getVersioningStore(xcontext).getXWikiDocumentArchive(this, xcontext);
      +            arch = getVersioningStore(xcontext).getXWikiDocumentArchive(this, xcontext);
       
                   // Put a copy of the archive in the soft reference for later use if needed.
                   setDocumentArchive(arch);
      

        Attachments

          Activity

            People

            • Assignee:
              sdumitriu Sergiu Dumitriu
              Reporter:
              aj Andreas Jonsson
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Date of First Response: