Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-8108

RestorePreviousVersionCommand throws nullPointer exception

    XMLWordPrintable

Details

    Description

      Steps to reproduce 

      In order to quickly reproduce the issue we are going to force assets to have subnodes

      1. Go to JCR app and navigate to /tours/shark_brian_warrick_0824.JPG and import the attached XML dam.tours.shark_brian_warrick_0824..JPG.test.xml
      2. Add restorePreviousVersion to the action bar in dam assets app: edit /dam-app-jcr/decorations/dam-assets-app/apps/dam.subApps.yaml to add it as follows: 
        versions:
                    items:
                      - name: showVersions
                      - name: restoreVersion
                      - name: restorePreviousVersion
        
      3. Open assets app and go to /tours/shark_brian_warrick_0824.JPG. Publish it to make sure there are versions available
      4. Click on restore previous action in the action bar

      Expected results

      Previous version is restored ok

      Actual results

      An error is thrown with no detailed information of the cause

      Workaround

      Using restore version action

      Development notes

      This error happens only when there are subnodes in the item. When debugging RestorePreviousVersionCommand you can see that the cause is a nullPointerException which is thrown in info.magnolia.commands.impl.RestorePreviousVersionCommand.getPreviousVersion(Node) method, specifically here:

      VersionIterator versionIterator = versionManager.getAllVersions(node);
      
              while (versionIterator.hasNext()) {
                  previousVersion = versionIterator.nextVersion();
              }
      

      versionManager.getAllVersions can return null in two scenarios, if versionedNode is null and if versionHistory is null. Therefore, if one of these situations occurs, the next instruction, versionIterator.hasNext(), will throw a null pointer exception.
      SOLUTION: add a null control before the while loop:

      proposed solution
       VersionIterator versionIterator = versionManager.getAllVersions(node);
      if(versionIterator!=null){
              while (versionIterator.hasNext()) {
                  previousVersion = versionIterator.nextVersion();
              }
      }
      

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                oanh.thai Oanh Thai Hoang
                jayala Jonathan Ayala
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Bug DoR
                    Task DoD

                    Time Tracking

                      Estimated:
                      Original Estimate - Not Specified
                      Not Specified
                      Remaining:
                      Remaining Estimate - 0d
                      0d
                      Logged:
                      Time Spent - 0.25d
                      0.25d