Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6195831

KeyboardFocusManager.setDefaultFocusTraversalKeys(..) throws ClassCastException instead of IAE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0u1
    • client-libs
    • None
    • b27
    • x86
    • windows_2000
    • Verified

      According to the specs J2SE 1.4.2 and 5.0:
      KeyboardFocusManager.setDefaultFocusTraversalKeys(int id, Set keystrokes)
      "Throws: IllegalArgumentException - .. if any Object in
      keystrokes is not an AWTKeyStroke"

      However, the J2SE implementations 1.4.2 and 1.5.0 throw ClassCastException
      instead of expected IllegalArgumentException.

      The code sample below demonstrates the problem:
      -------------- TestFT14.java -----------------
      import java.awt.*;
      import java.util.*;

      public class TestFT14 {
          KeyboardFocusManager currentKFM =
                  KeyboardFocusManager.getCurrentKeyboardFocusManager();

          public static void main(String[] args) {
              new TestFT14().test();
          }

          private void test() {
              AWTKeyStroke key = AWTKeyStroke.getAWTKeyStroke("ENTER");
              HashSet set = new HashSet();
              set.add(key);
              set.add(new Object());

              try {
                  currentKFM.setDefaultFocusTraversalKeys(
                         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
              } catch(Exception e) {
                  if (e instanceof IllegalArgumentException) {
                      System.out.println("KFM: OKAY");
                  } else {
                      e.printStackTrace();
                      System.out.println("KFM: unexpected " + e + " thrown instead of IAE");
                  }
              }
          }
      }
      ---------------------------------------------------
      -------------- Output for 1.4.2 -------------------
      e:\>c:\jdk1.4.2\bin\java -classpath . TestFT14
      java.lang.ClassCastException
              at java.awt.KeyboardFocusManager.setDefaultFocusTraversalKeys(KeyboardFocusManager.java:952)
              at TestFT14.test(TestFT14.java:19)
              at TestFT14.main(TestFT14.java:9)
      KFM: unexpected java.lang.ClassCastException thrown instead of IAE
      ---------------------------------------------------

      ###@###.### 2004-11-16 11:06:39 GMT

            vbaranovsunw Vyacheslav Baranov (Inactive)
            visaenko Vasily Isaenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: