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

FocusTraversalPolicy.getInitialComponent does not work as expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 1.4.2
    • client-libs
    • b29
    • x86
    • windows_2000
    • Verified

      The specification states for FocusTraversalPolicy.getInitialComponent:
      "Throws: IllegalArgumentException - if window is null"

      However, J2SE 1.4.2 and 1.5 throw NPE instead IAE.

      The following code sample demonstrates the problem:
      --------------------- TestFTP.java ----------------------
      import java.awt.*;

      public class TestFTP {

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

          private void test() {
              CustomFocusTraversalPolicy cftp =
                       new CustomFocusTraversalPolicy();
              try {
                  cftp.getInitialComponent(null);
              } catch (IllegalArgumentException iae) {
              } catch (Exception e) {
                  System.out.println("Unexpected exception thrown: " + e);
              }
          }

          private class CustomFocusTraversalPolicy extends FocusTraversalPolicy {
          
              public Component getComponentAfter(Container focusCycleRoot,
                                                 Component aComponent) {
                  return null;
              }
              
              public Component getComponentBefore(Container focusCycleRoot,
                                                  Component aComponent) {
                  return null;
              }
              
              public Component getDefaultComponent(Container focusCycleRoot) {
                  return null;
              }
              
              public Component getFirstComponent(Container focusCycleRoot) {
                  return null;
              }
       
              public Component getLastComponent(Container focusCycleRoot) {
                  return null;
              }
          }
      }
      ---------------------------------------------------------------------
      ------------------------ Output -------------------------------------
      Unexpected exception thrown: java.lang.NullPointerException
      ---------------------------------------------------------------------
      ###@###.### 2005-2-03 15:47:00 GMT

            dav Andrei Dmitriev (Inactive)
            visaenko Vasily Isaenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: