Hi there,

this patch fixes DefaultStyledDocument.setParagraphAttributes(), so that
it doesn't hang in an infinite loop like in the testcase of bug#

Also, I put this operation into a write lock as pointed out in the
OReilly Swing book.

2005-12-19  Roman Kennke  <[EMAIL PROTECTED]>

        PR classpath/24195
        * javax/swing/text/DefaultStyledDocument.java
        (setParagraphAttributes): Obtain lock for this operation. Exit
loop
        after last paragraph element.

/Roman
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- javax/swing/text/DefaultStyledDocument.java	14 Dec 2005 19:56:45 -0000	1.19
+++ javax/swing/text/DefaultStyledDocument.java	19 Dec 2005 10:21:39 -0000	1.20
@@ -1380,16 +1380,22 @@
                                      AttributeSet attributes,
                                      boolean replace)
   {
+    writeLock();
     int index = offset;
     while (index < offset + length)
       {
         AbstractElement par = (AbstractElement) getParagraphElement(index);
+        // If we have already seen this paragraph element, then exit the loop.
+        if (par.getEndOffset() + 1 == index)
+          break;
+
         AttributeContext ctx = getAttributeContext();
         if (replace)
           par.removeAttributes(par);
         par.addAttributes(attributes);
-        index = par.getElementCount();
+        index = par.getEndOffset() + 1;
       }
+    writeUnlock();
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to