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