Skip to content

Commit

Permalink
Fix NPE in UndoManager2.addUndo fixes #2004
Browse files Browse the repository at this point in the history
TriggeredOperations.getTriggeringOperation() can return null after
TriggeredOperations.remove()

#2004
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 27, 2024
1 parent d6c128e commit 9d6981f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ private void removeAllChildren() {
}

/**
* Return the operation that triggered the other operations in this
* composite.
* Return the operation that triggered the other operations in this composite.
*
* @return the IUndoableOperation that triggered the other children.
* @return the IUndoableOperation that triggered the other children or
* <code>null</code> if the triggeringOperation was removed
* @see TriggeredOperations#remove(IUndoableOperation)
*/
public IUndoableOperation getTriggeringOperation() {
return triggeringOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ public void changePerformed(Change change, boolean successful) {
@Override
public void addUndo(String name, Change change) {
if (fActiveOperation != null) {
UndoableOperation2ChangeAdapter operation= (UndoableOperation2ChangeAdapter)fActiveOperation.getTriggeringOperation();
operation.setUndoChange(change);
operation.setLabel(name);
if (fActiveOperation.getTriggeringOperation() instanceof UndoableOperation2ChangeAdapter operation) {
operation.setUndoChange(change);
operation.setLabel(name);
}
fOperationHistory.add(fActiveOperation);
fActiveOperation= null;
}
Expand Down

0 comments on commit 9d6981f

Please sign in to comment.