Skip to content

Commit 9d6981f

Browse files
committed
Fix NPE in UndoManager2.addUndo fixes eclipse-platform#2004
TriggeredOperations.getTriggeringOperation() can return null after TriggeredOperations.remove() eclipse-platform#2004
1 parent d6c128e commit 9d6981f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/operations/TriggeredOperations.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,11 @@ private void removeAllChildren() {
295295
}
296296

297297
/**
298-
* Return the operation that triggered the other operations in this
299-
* composite.
298+
* Return the operation that triggered the other operations in this composite.
300299
*
301-
* @return the IUndoableOperation that triggered the other children.
300+
* @return the IUndoableOperation that triggered the other children or
301+
* <code>null</code> if the triggeringOperation was removed
302+
* @see TriggeredOperations#remove(IUndoableOperation)
302303
*/
303304
public IUndoableOperation getTriggeringOperation() {
304305
return triggeringOperation;

bundles/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ public void changePerformed(Change change, boolean successful) {
173173
@Override
174174
public void addUndo(String name, Change change) {
175175
if (fActiveOperation != null) {
176-
UndoableOperation2ChangeAdapter operation= (UndoableOperation2ChangeAdapter)fActiveOperation.getTriggeringOperation();
177-
operation.setUndoChange(change);
178-
operation.setLabel(name);
176+
if (fActiveOperation.getTriggeringOperation() instanceof UndoableOperation2ChangeAdapter operation) {
177+
operation.setUndoChange(change);
178+
operation.setLabel(name);
179+
}
179180
fOperationHistory.add(fActiveOperation);
180181
fActiveOperation= null;
181182
}

0 commit comments

Comments
 (0)