Hi,

This fixes bug#22966.

Note that I added an assert statement, AFAICS the first assert statement
in Classpath. This is really a case where I consider this useful. If
anybody has a problem with this, then scream and yell and I'll change
this into an if statement with exception.

I also added a testcase to Mauve for this bug, so that a regression gets
noticed. The GapContent is a low level class used in all text
components. If it's behaviour changes, then this breaks the text
components in subtle ways.

2005-09-08  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/GapContent.java
        Fixes Bug #22966.
        (GapContentPosition.getOffset): Added assertion to check for
        consistent state of the Position. Fixed condition in
        if-statement.
        (serialVersionUID): Updated serialVersionUID to match JDK1.5.
        (shiftGap): If gapStart == newGapStart, then return immediatly.

/Roman

Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.24
diff -u -r1.24 GapContent.java
--- javax/swing/text/GapContent.java	7 Sep 2005 18:07:57 -0000	1.24
+++ javax/swing/text/GapContent.java	8 Sep 2005 09:51:37 -0000
@@ -39,8 +39,8 @@
 package javax.swing.text;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.ListIterator;
 
 import javax.swing.undo.UndoableEdit;
@@ -59,7 +59,6 @@
 public class GapContent
     implements AbstractDocument.Content, Serializable
 {
-
   /**
    * A [EMAIL PROTECTED] Position} implementation for <code>GapContent</code>.
    */
@@ -114,14 +113,18 @@
      */
     public int getOffset()
     {
-      if (mark <= gapEnd)
+      // Check precondition.
+      assert(mark <= gapStart || mark > gapEnd);
+
+      if (mark <= gapStart)
         return mark;
       else
         return mark - (gapEnd - gapStart);
     }
   }
 
-  private static final long serialVersionUID = 8374645204155842629L;
+  /** The serialization UID (compatible with JDK1.5). */
+  private static final long serialVersionUID = -6226052713477823730L;
 
   /**
    * This is the default buffer size and the amount of bytes that a buffer is
@@ -148,7 +151,7 @@
    * The positions generated by this GapContent. They are kept in an ordered
    * fashion, so they can be looked up easily.
    */
-  LinkedList positions;
+  ArrayList positions;
 
   /**
    * Creates a new GapContent object.
@@ -169,7 +172,7 @@
     gapStart = 0;
     gapEnd = size - 1;
     buffer[size - 1] = '\n';
-    positions = new LinkedList();
+    positions = new ArrayList();
   }
 
   /**
@@ -415,6 +418,9 @@
    */
   protected void shiftGap(int newGapStart)
   {
+    if (newGapStart == gapStart)
+      return;
+
     int newGapEnd = newGapStart + (gapEnd - gapStart);
 
     // Update the positions between newGapEnd and (old) gapEnd. The marks
@@ -437,9 +443,7 @@
           }
       }
 
-    if (newGapStart == gapStart)
-      return;
-    else if (newGapStart < gapStart)
+    if (newGapStart < gapStart)
       {
         System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart
                          - newGapStart);

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to