# HG changeset patch # User bagiras # Date 1336142528 -14400 # Node ID 5d709010bb1df738a12101fb7677c07fd0782aef # Parent 39a7283fac84655b2f59206ebef0c43ad98203db 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19 Reviewed-by: art, anthony diff -r 39a7283fac84 -r 5d709010bb1d jdk/src/share/classes/java/awt/Component.java --- a/jdk/src/share/classes/java/awt/Component.java Fri May 04 13:15:49 2012 +0400 +++ b/jdk/src/share/classes/java/awt/Component.java Fri May 04 18:42:08 2012 +0400 @@ -7169,6 +7169,9 @@ * Set from its parent. If all ancestors of this Component have null * specified for the Set, then the current KeyboardFocusManager's default * Set is used. + *
+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or @@ -7182,8 +7185,7 @@ * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes - * contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, + * contains null, or if any keystroke represents a KEY_TYPED event, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.4 diff -r 39a7283fac84 -r 5d709010bb1d jdk/src/share/classes/java/awt/Container.java --- a/jdk/src/share/classes/java/awt/Container.java Fri May 04 13:15:49 2012 +0400 +++ b/jdk/src/share/classes/java/awt/Container.java Fri May 04 18:42:08 2012 +0400 @@ -3093,6 +3093,9 @@ * Set from its parent. If all ancestors of this Container have null * specified for the Set, then the current KeyboardFocusManager's default * Set is used. + *
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
@@ -3109,8 +3112,7 @@
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes
- * contains null, or if any Object in keystrokes is not an
- * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
+ * contains null, or if any keystroke represents a KEY_TYPED event,
* or if any keystroke already maps to another focus traversal
* operation for this Container
* @since 1.4
diff -r 39a7283fac84 -r 5d709010bb1d jdk/src/share/classes/java/awt/KeyboardFocusManager.java
--- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Fri May 04 13:15:49 2012 +0400
+++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Fri May 04 18:42:08 2012 +0400
@@ -991,12 +991,12 @@
/**
* Sets the default focus traversal keys for a given traversal operation.
- * This traversal key Set
will be in effect on all
- * Window
s that have no such Set
of
- * their own explicitly defined. This Set
will also be
- * inherited, recursively, by any child Component
of
- * those Windows
that has
- * no such Set
of its own explicitly defined.
+ * This traversal key {@code Set} will be in effect on all
+ * {@code Window}s that have no such {@code Set} of
+ * their own explicitly defined. This {@code Set} will also be
+ * inherited, recursively, by any child {@code Component} of
+ * those {@code Windows} that has
+ * no such {@code Set} of its own explicitly defined.
*
* The default values for the default focus traversal keys are * implementation-dependent. Sun recommends that all implementations for a @@ -1011,66 +1011,67 @@ *
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
TAB
on KEY_PRESSED
,
- * CTRL-TAB
on KEY_PRESSED
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
SHIFT-TAB
on KEY_PRESSED
,
- * CTRL-SHIFT-TAB
on KEY_PRESSED
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
Set
;
- * Collections.EMPTY_SET
is recommended.
+ * To disable a traversal key, use an empty {@code Set};
+ * {@code Collections.EMPTY_SET} is recommended.
*
- * Using the AWTKeyStroke
API, client code can
+ * Using the {@code AWTKeyStroke} API, client code can
* specify on which of two
- * specific KeyEvent
s, KEY_PRESSED
or
- * KEY_RELEASED
, the focus traversal operation will
- * occur. Regardless of which KeyEvent
is specified,
- * however, all KeyEvent
s related to the focus
- * traversal key, including the associated KEY_TYPED
+ * specific {@code KeyEvent}s, {@code KEY_PRESSED} or
+ * {@code KEY_RELEASED}, the focus traversal operation will
+ * occur. Regardless of which {@code KeyEvent} is specified,
+ * however, all {@code KeyEvent}s related to the focus
+ * traversal key, including the associated {@code KEY_TYPED}
* event, will be consumed, and will not be dispatched
- * to any Component
. It is a runtime error to
- * specify a KEY_TYPED
event as
+ * to any {@code Component}. It is a runtime error to
+ * specify a {@code KEY_TYPED} event as
* mapping to a focus traversal operation, or to map the same event to
* multiple default focus traversal operations.
+ *
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of
- * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
,
- * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
,
- * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
, or
- * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
- * @param keystrokes the Set of AWTKeyStroke
s for the
+ * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
+ * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}
+ * @param keystrokes the Set of {@code AWTKeyStroke}s for the
* specified operation
* @see #getDefaultFocusTraversalKeys
* @see Component#setFocusTraversalKeys
* @see Component#getFocusTraversalKeys
* @throws IllegalArgumentException if id is not one of
- * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
,
- * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
,
- * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
, or
- * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
,
- * or if keystrokes is null
,
- * or if keystrokes contains null
,
- * or if any Object
in
- * keystrokes is not an AWTKeyStroke
,
+ * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
+ * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS},
+ * or if keystrokes is {@code null},
+ * or if keystrokes contains {@code null},
* or if any keystroke
- * represents a KEY_TYPED
event,
+ * represents a {@code KEY_TYPED} event,
* or if any keystroke already maps
* to another default focus traversal operation
* @beaninfo
@@ -1090,20 +1091,12 @@
Set oldKeys;
synchronized (this) {
- for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) {
- Object obj = iter.next();
+ for (AWTKeyStroke keystroke : keystrokes) {
- if (obj == null) {
+ if (keystroke == null) {
throw new IllegalArgumentException("cannot set null focus traversal key");
}
- // Fix for 6195831:
- //According to javadoc this method should throw IAE instead of ClassCastException
- if (!(obj instanceof AWTKeyStroke)) {
- throw new IllegalArgumentException("object is expected to be AWTKeyStroke");
- }
- AWTKeyStroke keystroke = (AWTKeyStroke)obj;
-
if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
}
diff -r 39a7283fac84 -r 5d709010bb1d jdk/src/share/classes/javax/swing/JComponent.java
--- a/jdk/src/share/classes/javax/swing/JComponent.java Fri May 04 13:15:49 2012 +0400
+++ b/jdk/src/share/classes/javax/swing/JComponent.java Fri May 04 18:42:08 2012 +0400
@@ -4148,6 +4148,9 @@
* Refer to
* {@link java.awt.Component#setFocusTraversalKeys}
* for a complete description of this method.
+ *
+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or @@ -4160,8 +4163,7 @@ * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes - * contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, + * contains null, or if any keystroke represents a KEY_TYPED event, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.5