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

LayoutFocusTraversalPolicy.getComponentAfter() shouldn't raise NPE

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: auR10023 Date: 11/17/2000


        
      The next methods of javax.swing.LayoutFocusTraversalPolicy:

          getComponentAfter(Container, Component)
          getComponentBefore(Container, Component)
          getFirstComponent(Container)
          getLastComponent(Container)
        
      incorrectly raise NullPointerException when Container is null.
        
      But javadoc for these methods states:
        
       getComponentAfter(), getComponentBefore()
        
      ...
      Throws:
                IllegalArgumentException - if focusCycleRoot is not a focus cycle root of
                aComponent, or if either focusCycleRoot or aComponent is null
      ...
        
        
       getFirstComponent() and getLastComponent()

      ...
      Throws:
                IllegalArgumentException - if focusCycleRoot is null
      ...


      ----Test.java------
      import javax.swing.*;
      import java.awt.*;

      public class Test {
          public static void main (String[] args) {
              LayoutFocusTraversalPolicy policy = new LayoutFocusTraversalPolicy();
              Component comp = new JTextField();
              try {
                  policy.getComponentAfter(null, comp);
              } catch(IllegalArgumentException e) {
                  System.out.println("IllegalArgumentException was obtained");
              } catch(NullPointerException e) {
                  System.out.println("NullPointerException was obtained");
              }
          }
      }

      -----Output--------

      NullPointerException was obtained

      ======================================================================

            svioletsunw Scott Violet (Inactive)
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: