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.
In fixing issue 8692, a change was made to BaseDocument and BaseDocumentEvent that asserts that the last edit made will be the first edit undone. While quite sensible, this fails to be useful and does not have anything to do with the bug fix itself. In fact, it blocks a perfectly reasonable use of the document and hinders managing its undoable edits. For the XML Schema editor in the Enterprise Pack, we have a model that is backed by a text file, which is stored in memory in a BaseDocument instance. The document is editable by the user via a CloneableEditor. The model is editable directly via a graphical interface, and changes made to the model are flushed to the document. Because the model employs a fast tree-based undo/redo support, we want to manage the model's undoable edits as well as the document's undoable edits (otherwise, syncing the model with the text is very expensive). This is described here: http://xml.netbeans.org/specs/undo/ As such, we have an undo queue with both document edits and model edits. When the model edits are undone, they operate on the model and subsequently flush the change back to the document. The document edits related to this model change are discarded, as they are not relevant. Anything the model does to the document is assumed to be perfect and does not need to be 'undone', unlike edits made by the user. Because the model flushed its change to the document when its edit was undone, the BaseDocument lastModifyUndoEdit reference was changed. Subsequently, undoing any document edit made by the user prior to the model change will result in a CannotUndoException. As you can imagine, this is a disaster for us. After spending three weeks developing this undo/redo solution, following Yarda's explicit directions, we have been crippled by an assertion that, at best, catches a problem that may never occur. Another reason why the assertion is of little or no value is that it does not guard against concurrent changes *after* the last edit is undone. So it only catches the mistake the first time, but after that all sorts of awful things could be done. It is of no use and it prevents our perfectly reasonable attempts at using BaseDocument from succeeding. After all, we are the controller of the document, we should be allowed to manage the undoable edits and document contents as we see fit.
Raising to P1, as the team agreed that this blocks our progress in this area. Either this needs to be fixed or we need someone in NetBeans to explain how to work around the issue.
OK, I will remove the assertion. It was useful when the CloneableEditorSupport did the adding of the undoable events asynchronously to prevent BaseDocument <-> UndoManager deadlocks - to ensure that there will not be undo called prior physical adding of the undoable edit to the UndoManager (or more precisely CES.getUndoRedo()). However Yarda has changed the UM in CES to first write-lock the document to avoid the deadlocks and restored synchronous adding of the UEs. I hope that you reuse the UM from CES.getUndoRedo() for your solution - otherwise you would have two active UMs which would be problematic.
Fixed in trunk: Checking in BaseDocumentEvent.java; /cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v <-- BaseDocumentEvent.java new revision: 1.26; previous revision: 1.25 I will integrate into release55 branch as well.
Diff: http://www.netbeans.org/source/browse/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java.diff?r1=1.25&r2=1.26
Integrated into release55: Checking in libsrc/org/netbeans/editor/BaseDocumentEvent.java; /cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v <-- BaseDocumentEvent.java new revision: 1.24.40.2; previous revision: 1.24.40.1