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

XWikiDocument#restoreContext doesn't restore properly the script context

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 4.2-milestone-1
    • 4.1.2
    • Old Core
    • None
    • Trivial
    • N/A
    • N/A

    Description

      If you execute the following code:

      {{groovy}}
      import com.xpn.xwiki.doc.XWikiDocument;
      
      def context = xcontext.getContext();
      def backup = null;
      
      try {
        def targetDoc = xwiki.getDocument("Space.Page").getDoc();
        backup = new HashMap<String, Object>();
        XWikiDocument.backupContext(backup, context);
        targetDoc.setAsContextDoc(context);
      
        // ...
      } finally {
        if (backup != null) {
          println doc.getFullName();
          XWikiDocument.restoreContext(backup, context);
          println doc.getFullName();
        }
      }
      {{/groovy}}
      

      the second printed full name is "Space.Page" instead of the current document. The reason is that XWikiDocument#restoreContext restores the context document after accessing the Velocity context and thus the script context (re)initialization triggered by the Velocity manager is done using the current context document.

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              mflorea Marius Dumitru Florea
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: