I fixed AbstractDocument.insertString to have the locking/unlocking in a
try finally block for more robustness. Also, as pointed out in this fine
article:
http://java.sun.com/products/jfc/tsc/articles/text/concurrency/index.html
the lock has to be held until all listeners are notified.

2006-02-07  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/AbstractDocument.java
        (insertString): Enclose locking/unlocking in try-finally block
        and also keep locked while notifying the listeners.

/Roman
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.43
diff -u -r1.43 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java	5 Jan 2006 20:15:34 -0000	1.43
+++ javax/swing/text/AbstractDocument.java	7 Feb 2006 16:39:38 -0000
@@ -538,18 +538,24 @@
     DefaultDocumentEvent event =
       new DefaultDocumentEvent(offset, text.length(),
 			       DocumentEvent.EventType.INSERT);
-    
-    writeLock();
-    UndoableEdit undo = content.insertString(offset, text);
-    if (undo != null)
-      event.addEdit(undo);
 
-    insertUpdate(event, attributes);
-    writeUnlock();
-
-    fireInsertUpdate(event);
-    if (undo != null)
-      fireUndoableEditUpdate(new UndoableEditEvent(this, undo));
+    try
+      {
+        writeLock();
+        UndoableEdit undo = content.insertString(offset, text);
+        if (undo != null)
+          event.addEdit(undo);
+
+        insertUpdate(event, attributes);
+
+        fireInsertUpdate(event);
+        if (undo != null)
+          fireUndoableEditUpdate(new UndoableEditEvent(this, undo));
+      }
+    finally
+      {
+        writeUnlock();
+      }
   }
 
   /**

Reply via email to