diff --git a/src/share/classes/java/awt/Component.java b/src/share/classes/java/awt/Component.java index 63fe2a80be99c2d3d1688a7a2b876ec0d9d4b758..00d363c1162840e2fea7be60796bcef4aa8c3cef 100644 --- a/src/share/classes/java/awt/Component.java +++ b/src/share/classes/java/awt/Component.java @@ -7169,6 +7169,9 @@ public abstract class Component implements ImageObserver, MenuContainer, * 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 @@ public abstract class Component implements ImageObserver, MenuContainer, * 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 --git a/src/share/classes/java/awt/Container.java b/src/share/classes/java/awt/Container.java index 03b0f7faa04fb48fd0163cefc91a54992ad68906..99cbdaff12459a0a84b0d741a96641c2b4bae535 100644 --- a/src/share/classes/java/awt/Container.java +++ b/src/share/classes/java/awt/Container.java @@ -3093,6 +3093,9 @@ public class Container extends Component { * 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 @@ public class Container extends Component {
* 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 --git a/src/share/classes/java/awt/KeyboardFocusManager.java b/src/share/classes/java/awt/KeyboardFocusManager.java
index 3ccf5b70d3603dce872ccadec18049c52d9d61e3..7b8b9f41e256743a3a3684dceb4f05ead7dc01b0 100644
--- a/src/share/classes/java/awt/KeyboardFocusManager.java
+++ b/src/share/classes/java/awt/KeyboardFocusManager.java
@@ -991,12 +991,12 @@ public abstract class KeyboardFocusManager
/**
* Sets the default focus traversal keys for a given traversal operation.
- * This traversal key Set will be in effect on all
- * Windows 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 @@ public abstract class KeyboardFocusManager *
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYSTAB on KEY_PRESSED,
- * CTRL-TAB on KEY_PRESSEDKeyboardFocusManager.BACKWARD_TRAVERSAL_KEYSSHIFT-TAB on KEY_PRESSED,
- * CTRL-SHIFT-TAB on KEY_PRESSEDKeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYSKeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYSSet;
- * 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 KeyEvents, KEY_PRESSED or
- * KEY_RELEASED, the focus traversal operation will
- * occur. Regardless of which KeyEvent is specified,
- * however, all KeyEvents 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 AWTKeyStrokes 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 @@ public abstract class KeyboardFocusManager
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 --git a/src/share/classes/javax/swing/JComponent.java b/src/share/classes/javax/swing/JComponent.java
index 78bc5c4f64891230a6da8d873f9ffa70f665c46d..83f88bfbfdcfb1b51c767ecfa29d63303bc49e6c 100644
--- a/src/share/classes/javax/swing/JComponent.java
+++ b/src/share/classes/javax/swing/JComponent.java
@@ -4148,6 +4148,9 @@ public abstract class JComponent extends Container implements Serializable,
* 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 @@ public abstract class JComponent extends Container implements Serializable, * 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