Border case for Position implementation, run the testcase below. If "Two" is instead inserted at position 3, or if the original position was at 5 then everything works, so this is a boundary case when the string is inserted exactly at the offset of a Position. ***TESTCASE*** expected output: 8 actual output: 4 import javax.swing.text.*; public class PositionExample { public static void main(String[] args) throws BadLocationException { PlainDocument doc = new PlainDocument(); doc.insertString(0, "One Three Four", null); Position pos = doc.createPosition(4); doc.insertString(4, "Two ", null); System.out.println (pos.getOffset()); } }
I'll look at this.
This is fixed in CVS head.
Subject: Bug 24105 CVSROOT: /cvsroot/classpath Module name: classpath Branch: Changes by: Roman Kennke <rabbit78@savannah.gnu.org> 05/09/29 17:32:19 Modified files: . : ChangeLog javax/swing/text: GapContent.java Log message: 2005-09-29 Roman Kennke <kennke@aicas.com> Fixes Bug #24105 * javax/swing/text/GapContent.java (GapContentPosition.getOffset): Adjusted assert statement. (shiftGap): Adjusted index in getPositionsInRange call. Call resetMarksAtZero if gapStart has moved to 0. (replace): Call shiftGap and shiftGapEndUp only if necessary. (resetMarksAtZero): New method. CVSWeb URLs: http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.5033&tr2=1.5034&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/javax/swing/text/GapContent.java.diff?tr1=1.26&tr2=1.27&r1=text&r2=text