--- old/src/share/classes/java/awt/Component.java 2012-04-25 16:03:58.121779200 +0400 +++ new/src/share/classes/java/awt/Component.java 2012-04-25 16:03:57.351735200 +0400 @@ -7169,6 +7169,10 @@ * 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 +7186,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 --- old/src/share/classes/java/awt/Container.java 2012-04-25 16:04:05.701212700 +0400 +++ new/src/share/classes/java/awt/Container.java 2012-04-25 16:04:04.991172100 +0400 @@ -3093,6 +3093,10 @@ * 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 +3113,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 --- old/src/share/classes/java/awt/KeyboardFocusManager.java 2012-04-25 16:04:12.699613000 +0400 +++ new/src/share/classes/java/awt/KeyboardFocusManager.java 2012-04-25 16:04:11.976571700 +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 - * 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,68 @@ * Default * * - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS} * Normal forward keyboard traversal - * TAB on KEY_PRESSED, - * CTRL-TAB on KEY_PRESSED + * {@code TAB} on {@code KEY_PRESSED}, + * {@code CTRL-TAB} on {@code KEY_PRESSED} * * - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS} * Normal reverse keyboard traversal - * SHIFT-TAB on KEY_PRESSED, - * CTRL-SHIFT-TAB on KEY_PRESSED + * {@code SHIFT-TAB} on {@code KEY_PRESSED}, + * {@code CTRL-SHIFT-TAB} on {@code KEY_PRESSED} * * - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS} * Go up one focus traversal cycle * none * * - * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS} * Go down one focus traversal cycle * none * * * - * To disable a traversal key, use an empty 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 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 +1092,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"); } --- old/src/share/classes/javax/swing/JComponent.java 2012-04-25 16:04:19.551004900 +0400 +++ new/src/share/classes/javax/swing/JComponent.java 2012-04-25 16:04:18.815962800 +0400 @@ -4149,6 +4149,10 @@ * 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 @@ -4161,8 +4165,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