1 /* |
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* @test |
|
25 @bug 7146146 |
|
26 @summary Deadlock between subclass of AbstractDocument and UndoManager |
|
27 @author Pavel Porvatov |
|
28 */ |
|
29 |
|
30 import javax.swing.text.BadLocationException; |
|
31 import javax.swing.text.PlainDocument; |
|
32 import javax.swing.text.StringContent; |
|
33 import javax.swing.undo.UndoManager; |
|
34 |
|
35 public class bug7146146 { |
|
36 public static void main(String[] args) throws Exception { |
|
37 for (int i = 0; i < 1000; i++) { |
|
38 System.out.print("Iteration " + i); |
|
39 |
|
40 test(); |
|
41 |
|
42 System.out.print(" passed"); |
|
43 } |
|
44 } |
|
45 |
|
46 private static void test() throws Exception { |
|
47 final PlainDocument doc = new PlainDocument(new StringContent()); |
|
48 final UndoManager undoManager = new UndoManager(); |
|
49 |
|
50 doc.addUndoableEditListener(undoManager); |
|
51 doc.insertString(0, "<Test 1>", null); |
|
52 |
|
53 Thread t1 = new Thread("Thread 1") { |
|
54 @Override |
|
55 public void run() { |
|
56 try { |
|
57 doc.insertString(0, "<Test 2>", null); |
|
58 } catch (BadLocationException e) { |
|
59 throw new RuntimeException(e); |
|
60 } |
|
61 } |
|
62 }; |
|
63 |
|
64 Thread t2 = new Thread("Thread 2") { |
|
65 @Override |
|
66 public void run() { |
|
67 undoManager.undo(); |
|
68 } |
|
69 }; |
|
70 |
|
71 t1.start(); |
|
72 t2.start(); |
|
73 |
|
74 t1.join(); |
|
75 t2.join(); |
|
76 } |
|
77 } |
|