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 - CannotUndoException removes UndoableEdit from undo vector
Summary: CannotUndoException removes UndoableEdit from undo vector
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 7.2
Hardware: All All
: P2 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks: 48427
  Show dependency tree
 
Reported: 2012-01-11 13:29 UTC by Jan Becicka
Modified: 2012-03-01 11:02 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.