7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
authorbagiras
Fri, 04 May 2012 18:42:08 +0400
changeset 12643 5d709010bb1d
parent 12642 39a7283fac84
child 12644 087eca2f351b
7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19 Reviewed-by: art, anthony
jdk/src/share/classes/java/awt/Component.java
jdk/src/share/classes/java/awt/Container.java
jdk/src/share/classes/java/awt/KeyboardFocusManager.java
jdk/src/share/classes/javax/swing/JComponent.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.
+     * <p>
+     * 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
--- 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.
+     * <p>
+     * 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
--- 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 <code>Set</code> will be in effect on all
-     * <code>Window</code>s that have no such <code>Set</code> of
-     * their own explicitly defined. This <code>Set</code> will also be
-     * inherited, recursively, by any child <code>Component</code> of
-     * those <code>Windows</code> that has
-     * no such <code>Set</code> 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.
      * <p>
      * The default values for the default focus traversal keys are
      * implementation-dependent. Sun recommends that all implementations for a
@@ -1011,66 +1011,67 @@
      *    <th>Default</th>
      * </tr>
      * <tr>
-     *    <td><code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code></td>
+     *    <td>{@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}</td>
      *    <td>Normal forward keyboard traversal</td>
-     *    <td><code>TAB</code> on <code>KEY_PRESSED</code>,
-     *        <code>CTRL-TAB</code> on <code>KEY_PRESSED</code></td>
+     *    <td>{@code TAB} on {@code KEY_PRESSED},
+     *        {@code CTRL-TAB} on {@code KEY_PRESSED}</td>
      * </tr>
      * <tr>
-     *    <td><code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code></td>
+     *    <td>{@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}</td>
      *    <td>Normal reverse keyboard traversal</td>
-     *    <td><code>SHIFT-TAB</code> on <code>KEY_PRESSED</code>,
-     *        <code>CTRL-SHIFT-TAB</code> on <code>KEY_PRESSED</code></td>
+     *    <td>{@code SHIFT-TAB} on {@code KEY_PRESSED},
+     *        {@code CTRL-SHIFT-TAB} on {@code KEY_PRESSED}</td>
      * </tr>
      * <tr>
-     *    <td><code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code></td>
+     *    <td>{@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}</td>
      *    <td>Go up one focus traversal cycle</td>
      *    <td>none</td>
      * </tr>
      * <tr>
-     *    <td><code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code></td>
+     *    <td>{@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}</td>
      *    <td>Go down one focus traversal cycle</td>
      *    <td>none</td>
      * </tr>
      * </table>
      *
-     * To disable a traversal key, use an empty <code>Set</code>;
-     * <code>Collections.EMPTY_SET</code> is recommended.
+     * To disable a traversal key, use an empty {@code Set};
+     * {@code Collections.EMPTY_SET} is recommended.
      * <p>
-     * Using the <code>AWTKeyStroke</code> API, client code can
+     * Using the {@code AWTKeyStroke} API, client code can
      * specify on which of two
-     * specific <code>KeyEvent</code>s, <code>KEY_PRESSED</code> or
-     * <code>KEY_RELEASED</code>, the focus traversal operation will
-     * occur. Regardless of which <code>KeyEvent</code> is specified,
-     * however, all <code>KeyEvent</code>s related to the focus
-     * traversal key, including the associated <code>KEY_TYPED</code>
+     * 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 <code>Component</code>. It is a runtime error to
-     * specify a <code>KEY_TYPED</code> 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.
+     * <p>
+     * This method may throw a {@code ClassCastException} if any {@code Object}
+     * in {@code keystrokes} is not an {@code AWTKeyStroke}.
      *
      * @param id one of
-     *        <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
-     *        <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
-     *        <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
-     *        <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>
-     * @param keystrokes the Set of <code>AWTKeyStroke</code>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
-     *         <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
-     *         <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
-     *         <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
-     *         <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>,
-     *         or if keystrokes is <code>null</code>,
-     *         or if keystrokes contains <code>null</code>,
-     *         or if any <code>Object</code> in
-     *         keystrokes is not an <code>AWTKeyStroke</code>,
+     *         {@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 <code>KEY_TYPED</code> 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");
                 }
--- 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.
+     * <p>
+     * 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