Hi,
the attached patch fixes the regressions in GapContent (and PlainDocument as
well). Additionally it contains minor fixes to pass all of the GapContent tests.

ChangeLog:

2006-05-02  Robert Schuster  <[EMAIL PROTECTED]>

        * javax/swing/text/GapContent.java:
        (GapContent): Restrict size argument by 2.
        (insertString): Changed expression from >= to >.
        (remove): Changed right side of expression to 'length - 1', changed
        exception message.
        (getChars): Throw exception if where below 0.
        (replace): Replaced call to setPositionsInRange() with
        resetMarksAtZero(), removed note.

cya
Robert
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.44
diff -u -r1.44 GapContent.java
--- javax/swing/text/GapContent.java	31 Mar 2006 15:38:08 -0000	1.44
+++ javax/swing/text/GapContent.java	2 May 2006 12:34:41 -0000
@@ -289,6 +289,7 @@
    */
   public GapContent(int size)
   {
+    size = Math.max(size, 2);
     buffer = (char[]) allocateArray(size);
     gapStart = 1;
     gapEnd = size;
@@ -351,7 +352,7 @@
       throw new BadLocationException("The where argument cannot be smaller"
                                      + " than the zero", where);
 
-    if (where >= length)
+    if (where > length)
       throw new BadLocationException("The where argument cannot be greater"
           + " than the content length", where);
 
@@ -376,9 +377,9 @@
     // check arguments
     int length = length();
 
-    if (where >= length)
+    if (where >= length - 1)
       throw new BadLocationException("the where argument cannot be greater"
-          + " than the content length", where);
+          + " or equal than the content length - 1", where);
     if ((where + nitems) > length)
       throw new BadLocationException("where + nitems cannot be greater"
           + " than the content length", where + nitems);
@@ -439,6 +440,8 @@
   {
     // check arguments
     int length = length();
+    if (where < 0)
+      throw new BadLocationException("the where argument may not be below zero", where);
     if (where >= length)
       throw new BadLocationException("the where argument cannot be greater"
           + " than the content length", where);
@@ -643,12 +646,8 @@
       {
         System.arraycopy(addItems, 0, buffer, gapStart, addSize);
         
-        // Position objects having their mark at the end of the gap
-        // (results in an offset equal to gapStart) should be moved down
-        // because the size of the gap will decrease by addSize and the
-        // offsets will increase by the same amount and the latter should
-        // not happen.
-        setPositionsInRange(gapEnd, 0, gapStart);
+        
+        resetMarksAtZero();
         
         gapStart += addSize;
       }

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to