author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
17906
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
1 |
/* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
4 |
* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
8 |
* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
14 |
* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
18 |
* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
21 |
* questions. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
22 |
*/ |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
23 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
24 |
import java.awt.Robot; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
25 |
import java.awt.Toolkit; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
26 |
import java.awt.event.ActionEvent; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
27 |
import java.awt.event.KeyEvent; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
28 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
29 |
import javax.swing.AbstractAction; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
30 |
import javax.swing.InputMap; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
31 |
import javax.swing.JFrame; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
32 |
import javax.swing.JMenuBar; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
33 |
import javax.swing.JMenuItem; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
34 |
import javax.swing.KeyStroke; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
35 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
36 |
import static java.awt.event.InputEvent.CTRL_DOWN_MASK; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
37 |
import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
38 |
import static javax.swing.JOptionPane.showMessageDialog; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
39 |
import static javax.swing.SwingUtilities.invokeAndWait; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
40 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
41 |
/* |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
42 |
* @test |
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
31442
diff
changeset
|
43 |
* @key headful |
17906
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
44 |
* @bug 8013370 |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
45 |
* @summary Ensure that key stroke is not null |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
46 |
* @author Sergey Malenkov |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
47 |
*/ |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
48 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
49 |
public class Test8013370 implements Runnable { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
51 |
Test8013370 task = new Test8013370(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
52 |
invokeAndWait(task); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
53 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
54 |
Robot robot = new Robot(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
55 |
robot.waitForIdle(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
56 |
robot.keyPress(KeyEvent.VK_CONTROL); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
57 |
robot.keyRelease(KeyEvent.VK_CONTROL); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
58 |
robot.waitForIdle(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
59 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
60 |
invokeAndWait(task); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
61 |
task.validate(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
62 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
63 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
64 |
private JFrame frame; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
65 |
private boolean error; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
66 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
67 |
@Override |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
68 |
public void run() { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
69 |
if (this.frame == null) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
70 |
JMenuBar menu = new JMenuBar() { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
71 |
@Override |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
72 |
protected boolean processKeyBinding(KeyStroke stroke, KeyEvent event, int condition, boolean pressed) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
73 |
if (stroke == null) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
74 |
Test8013370.this.error = true; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
75 |
return false; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
76 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
77 |
return super.processKeyBinding(stroke, event, condition, pressed); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
78 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
79 |
}; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
80 |
menu.add(new JMenuItem("Menu")); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
81 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
82 |
InputMap map = menu.getInputMap(WHEN_IN_FOCUSED_WINDOW); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
83 |
// We add exactly 10 actions because the ArrayTable is converted |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
84 |
// from a array to a hashtable when more than 8 values are added. |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
85 |
for (int i = 0; i < 9; i++) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
86 |
String name = " Action #" + i; |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
87 |
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A + i, CTRL_DOWN_MASK), name); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
88 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
89 |
menu.getActionMap().put(name, new AbstractAction(name) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
90 |
@Override |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
91 |
public void actionPerformed(ActionEvent event) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
92 |
showMessageDialog(null, getValue(NAME)); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
93 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
94 |
}); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
95 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
96 |
this.frame = new JFrame("8013370"); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
97 |
this.frame.setJMenuBar(menu); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
98 |
this.frame.setVisible(true); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
99 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
100 |
else { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
101 |
this.frame.dispose(); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
102 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
103 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
104 |
|
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
105 |
private void validate() { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
106 |
if (this.error) { |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
107 |
throw new Error("KeyStroke is null"); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
108 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
109 |
} |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
diff
changeset
|
110 |
} |