[MAGNOLIA-8108] RestorePreviousVersionCommand throws nullPointer exception Created: 31/May/21 Updated: 22/Jun/21 Resolved: 08/Jun/21 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | 6.2.8 |
| Fix Version/s: | 6.2.10 |
| Type: | Bug | Priority: | Neutral |
| Reporter: | Jonathan Ayala | Assignee: | Oanh Thai Hoang |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | VN-Implementation, maintenance | ||
| Remaining Estimate: | 0d | ||
| Time Spent: | 0.25d | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||
| Template: | |||||||||||||||||||||
| Acceptance criteria: |
Empty
|
||||||||||||||||||||
| Task DoD: |
[X]*
Doc/release notes changes? Comment present?
[X]*
Downstream builds green?
[X]*
Solution information and context easily available?
[X]*
Tests
[X]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||||||||||||||
| Bug DoR: |
[X]*
Steps to reproduce, expected, and actual results filled
[X]*
Affected version filled
|
||||||||||||||||||||
| Release notes required: |
Yes
|
||||||||||||||||||||
| Date of First Response: | |||||||||||||||||||||
| Sprint: | Maintenance 61 | ||||||||||||||||||||
| Story Points: | 2 | ||||||||||||||||||||
| Description |
Steps to reproduceIn order to quickly reproduce the issue we are going to force assets to have subnodes
Expected resultsPrevious version is restored ok Actual resultsAn error is thrown with no detailed information of the cause WorkaroundUsing restore version action Development notesThis 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. proposed solution VersionIterator versionIterator = versionManager.getAllVersions(node); if(versionIterator!=null){ while (versionIterator.hasNext()) { previousVersion = versionIterator.nextVersion(); } } |
| Comments |
| Comment by Oanh Thai Hoang [ 22/Jun/21 ] |
|
Hi akhamis, here is the thing changes: Check null for version node before restoring previous version |