author | pchelko |
Fri, 23 May 2014 19:43:14 +0400 | |
changeset 25104 | 9a002d75bd42 |
child 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
25104
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
1 |
/* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
4 |
* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
8 |
* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
13 |
* accompanied this code). |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
14 |
* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
18 |
* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
21 |
* questions. |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
22 |
*/ |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
23 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
24 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
25 |
/* |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
26 |
@test |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
27 |
@bug 8043610 |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
28 |
@summary Tests that JComponent invalidate, revalidate and repaint methods could |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
29 |
be called from any thread |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
30 |
@author Petr Pchelko |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
31 |
*/ |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
32 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
33 |
import sun.awt.SunToolkit; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
34 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
35 |
import javax.swing.*; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
36 |
import java.awt.*; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
37 |
import java.util.concurrent.CountDownLatch; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
38 |
import java.util.concurrent.atomic.AtomicReference; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
39 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
40 |
public class bug8043610 { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
41 |
private static volatile JFrame frame; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
42 |
private static volatile JComponent component; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
43 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
45 |
ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group"); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
46 |
ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG"); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
47 |
try { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
48 |
Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
49 |
stubThread.start(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
50 |
stubThread.join(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
51 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
52 |
CountDownLatch startSwingLatch = new CountDownLatch(1); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
53 |
new Thread(swingTG, () -> { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
54 |
SunToolkit.createNewAppContext(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
55 |
SwingUtilities.invokeLater(() -> { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
56 |
frame = new JFrame(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
57 |
component = new JLabel("Test Text"); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
58 |
frame.add(component); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
59 |
frame.setBounds(100, 100, 100, 100); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
60 |
frame.setVisible(true); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
61 |
startSwingLatch.countDown(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
62 |
}); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
63 |
}).start(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
64 |
startSwingLatch.await(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
65 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
66 |
AtomicReference<Exception> caughtException = new AtomicReference<>(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
67 |
Thread checkThread = new Thread(getRootThreadGroup(), () -> { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
68 |
try { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
69 |
component.invalidate(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
70 |
component.revalidate(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
71 |
component.repaint(new Rectangle(0, 0, 0, 0)); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
72 |
} catch (Exception e) { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
73 |
caughtException.set(e); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
74 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
75 |
}); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
76 |
checkThread.start(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
77 |
checkThread.join(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
78 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
79 |
if (caughtException.get() != null) { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
80 |
throw new RuntimeException("Failed. Caught exception!", caughtException.get()); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
81 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
82 |
} finally { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
83 |
new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
84 |
if (frame != null) { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
85 |
frame.dispose(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
86 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
87 |
})).start(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
88 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
89 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
90 |
|
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
91 |
private static ThreadGroup getRootThreadGroup() { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
92 |
ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
93 |
ThreadGroup parentTG = currentTG.getParent(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
94 |
while (parentTG != null) { |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
95 |
currentTG = parentTG; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
96 |
parentTG = currentTG.getParent(); |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
97 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
98 |
return currentTG; |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
99 |
} |
9a002d75bd42
8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents:
diff
changeset
|
100 |
} |