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.
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
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.
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
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.