author | vromero |
Thu, 05 Jan 2017 11:16:39 -0800 | |
changeset 43033 | c37b643739a7 |
parent 39858 | 882e63569349 |
child 46151 | 5fa789776f7d |
permissions | -rw-r--r-- |
39858
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
1 |
/* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
4 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
8 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
13 |
* accompanied this code). |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
14 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
18 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
21 |
* questions. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
22 |
*/ |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
23 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
24 |
/* @test |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
25 |
* @bug 6567433 |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
26 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
27 |
* @summary JList.updateUI() for invokes updateUI() on its cellrenderer via |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
28 |
* SwingUtilities.updateComponentTreeUI(). |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
29 |
* If the cellrenderer is a parent of this JList the method recurses |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
30 |
* endless. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
31 |
* This test tests that the fix is effective in avoiding recursion. |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
32 |
* |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
33 |
* @run main/othervm UpdateUIRecursionTest |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
34 |
*/ |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
35 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
36 |
import java.awt.BorderLayout; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
37 |
import java.awt.Component; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
38 |
import javax.swing.DefaultListCellRenderer; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
39 |
import javax.swing.JFrame; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
40 |
import javax.swing.JList; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
41 |
import javax.swing.JScrollPane; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
42 |
import javax.swing.ListCellRenderer; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
43 |
import javax.swing.SwingUtilities; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
44 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
45 |
public class UpdateUIRecursionTest extends JFrame implements ListCellRenderer { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
46 |
JList list; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
47 |
DefaultListCellRenderer renderer; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
48 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
49 |
public UpdateUIRecursionTest() { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
50 |
super("UpdateUIRecursionTest"); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
51 |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
52 |
setSize(400, 400); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
53 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
54 |
String[] listData = { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
55 |
"First", "Second", "Third", "Fourth", "Fifth", "Sixth" |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
56 |
}; |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
57 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
58 |
list = new JList(listData); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
59 |
list.setCellRenderer(this); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
60 |
renderer = new DefaultListCellRenderer(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
61 |
getContentPane().add(new JScrollPane(list), BorderLayout.CENTER); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
62 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
63 |
setVisible(true); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
64 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
65 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
66 |
public static void main(String[] args) throws Exception { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
67 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
68 |
SwingUtilities.invokeAndWait(new Runnable() { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
69 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
70 |
@Override |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
71 |
public void run() { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
72 |
UpdateUIRecursionTest obj = new UpdateUIRecursionTest(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
73 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
74 |
obj.test(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
75 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
76 |
obj.disposeUI(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
77 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
78 |
}); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
79 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
80 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
81 |
public void test() { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
82 |
list.updateUI(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
83 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
84 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
85 |
public void disposeUI() { |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
86 |
setVisible(false); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
87 |
dispose(); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
88 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
89 |
|
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
90 |
public Component getListCellRendererComponent(JList list, Object value, |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
91 |
int index, boolean isSelected, boolean cellHasFocus) |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
92 |
{ |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
93 |
return renderer.getListCellRendererComponent(list, value, index, |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
94 |
isSelected, cellHasFocus); |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
95 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
96 |
} |
882e63569349
6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff
changeset
|
97 |