This discussion is archived
0 Replies Latest reply: May 22, 2013 5:34 AM by user11952969 RSS

Possible bug in javax.swing.text.GapContent

user11952969 Newbie
Currently Being Moderated
Hi!

I think there's bug in the GapContent class. I suppose it is related to fixed bug from the past:
[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4496801]

The fix changed condition in method GapContent.insertString(int, String) to allow calling of HTMLDocument.insertBeforeEnd(Element, String) over body element.
I think it should be also changed condition in GapContent.remove(int, int) method. Following code shows how calling on UndoableEditListener.undo() is failing after mentioned fixed situation.
javax.swing.text.html.HTMLDocument doc = new javax.swing.text.html.HTMLDocument();
doc.setParser(new javax.swing.text.html.parser.ParserDelegator());
javax.swing.undo.UndoManager undoManager = new javax.swing.undo.UndoManager();
doc.addUndoableEditListener(undoManager);
javax.swing.text.Element html = doc.getRootElements()[0];
javax.swing.text.Element body = html.getElement(0);
doc.insertBeforeEnd(body, "anything");
try {
     undoManager.undo();
} catch(Exception e) {
     e.printStackTrace(System.err);
}
Note: Code will work when insertBeforeEnd is replaced by insertAfterStart.
Tested under JDK 1.6.0_43.
Stacktrace:
javax.swing.undo.CannotUndoException
     at javax.swing.text.GapContent$InsertUndo.undo(GapContent.java:856)
     at javax.swing.undo.CompoundEdit.undo(CompoundEdit.java:46)
     at javax.swing.text.AbstractDocument$DefaultDocumentEvent.undo(AbstractDocument.java:2788)
     at javax.swing.undo.UndoManager.undoTo(UndoManager.java:320)
     at javax.swing.undo.UndoManager.undo(UndoManager.java:398)
Can somebody confirm my concern?

Edited by: user11952969 on May 22, 2013 5:30 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points