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

Maybe race condition in loadDocumentArchive

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.0 M3
    • 3.0 M2
    • {Unused} Core
    • None
    • patch, bugfixingday
    • Trivial

    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

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

            Dates

              Created:
              Updated:
              Resolved: