Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
Name: sv35042 Date: 10/18/2002 FULL PRODUCT VERSION : java version "1.3.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01) Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode) FULL OPERATING SYSTEM VERSION : SunOS modeler 5.6 Generic_105181-29 sun4u sparc SUNW,Ultra-5_10 ADDITIONAL OPERATING SYSTEMS : all, I'd think A DESCRIPTION OF THE PROBLEM : The Javadoc for javax.swing.JTextArea says the "append" method is thread safe. It is not, and the error could result in loss of data from the document. The implementation uses this line and discards the possible BadLocationException: doc.insertString(doc.getLength(), str, null); Alternately, we could write the same code in 2 lines, with numbers: 1 int len=doc.getLength(); 2 doc.insertString(len,str,null); The problem occurs if line 1 executes, then some other thread alters the length of the document, then line 2 executes. The possible results are that the data is inserted at some place not the end of the document, or that an attempt is made to insert data beyond the end of the document, resulting in a BadLocationException, which is then discarded, thereby loosing the data. REPRODUCIBILITY : This bug can be reproduced occasionally. CUSTOMER WORKAROUND : Wrap the Document with a Document offering an append method and synchronize the append, insert, and remove methods. Then use the document's append method instead of JTextArea.append. (Note, wrapping the document on a JTextArea with wrapped lines brings about occasional exceptions in the event dispatch thread as noted in the bug with Sun internal review ID 163709.) (Review ID: 163721) ======================================================================
|