This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 207174

Summary: CannotUndoException removes UndoableEdit from undo vector
Product: platform Reporter: Jan Becicka <jbecicka>
Component: TextAssignee: Miloslav Metelka <mmetelka>
Status: RESOLVED FIXED    
Severity: normal CC: mmetelka
Priority: P2    
Version: 7.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on:    
Bug Blocks: 48427    

Description Jan Becicka 2012-01-11 13:29:04 UTC
If a custom UndoableEdit is added to undo stack using BaseDocument.addUndoableEdit and this edits throws CannotUndoException during undo, this edit is removed from undo stack and cannot be performed again.

The problem has 2 parts: 
package private indexOfNextAdd of UndoManager class is decremented regardless of success/failure of undoable edit.

UndoableEdits are not recovered from undo (their internal state is "hasBeenDone").

This improvements is needed for issue 48427
Comment 1 Jan Becicka 2012-01-12 12:39:02 UTC
I can workaround indexOfNextAdd using reflection:
try {
} catch (CannotUndoException ex) {
  Field index = javax.swing.undo.UndoManager.class.getDeclaredField("indexOfNextAdd");
  index.setAccessible(true);
  index.setInt(m, index.getInt(m) - 1);
}

but all UndoableEdits are Wrapped by WrapEdit, which delegates to some saveEdits etc... and I'm not able to recover them from hasBeenDone state.
Reassigning to Mila.
Comment 2 Miloslav Metelka 2012-02-28 14:04:30 UTC
Both o.o.awt.UndoRedo.Manager and o.o.text.UndoRedoManager are now stable in terms of failing myEdit.undo() or myEdit.redo().

http://hg.netbeans.org/jet-main/rev/b794e7191c99
Comment 3 Quality Engineering 2012-03-01 11:02:39 UTC
Integrated into 'main-golden', will be available in build *201203010400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/b794e7191c99
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #207174 - CannotUndoException removes UndoableEdit from undo vector.