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

I think there's bug in the GapContent class. I suppose it is related to fixed bug from the past:

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();
javax.swing.text.Element html = doc.getRootElements()[0];
javax.swing.text.Element body = html.getElement(0);
doc.insertBeforeEnd(body, "anything");
try {
} catch(Exception e) {
Note: Code will work when insertBeforeEnd is replaced by insertAfterStart.
Tested under JDK 1.6.0_43.
     at javax.swing.text.GapContent$InsertUndo.undo(
     at javax.swing.undo.CompoundEdit.undo(
     at javax.swing.text.AbstractDocument$DefaultDocumentEvent.undo(
     at javax.swing.undo.UndoManager.undoTo(
     at javax.swing.undo.UndoManager.undo(
Can somebody confirm my concern?

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


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