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

no check whether component has the focus before remove component

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.5
    • CPU:
      x86
    • OS:
      generic
    • Verification:
      Verified

      Description

      7/25/97: Oracle report:

      ==========================================
      When remove is called on a Component, no check is made to see if the Component
      or one of it's children has the focus. If a child has the focus, the next
      time FocusManager.focusNext() is called there is a NullPointerException
      because the method tries Components that are no longer in the tree.
      When a lightweight Component is hidden, if it or one of it's children has the
      focus, the focus must be changed to the next eligible Component.
      The Windowing system takes care of this for heavyweight Components.
      LightweightComponent.hide() needs to handle this.
      Exception occurred during event dispatching:
      java.lang.NullPointerException:
              at java.awt.FocusManager.focusNext(Window.java:518)
              at java.awt.FocusManager.focusNext(Window.java:504)
              at java.awt.Window.handleTabEvent(Window.java:332)
              at java.awt.Window.postProcessKeyEvent(Window.java:345)
              at java.awt.Component.dispatchEventImpl(Component.java:1501)
              at java.awt.Container.dispatchEventImpl(Container.java:837)
              at java.awt.Window.dispatchEventImpl(Window.java:401)
              at java.awt.Component.dispatchEvent(Component.java:1393)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

      This NullPointerException is actually caused by a different problem! I shall
      open another bug for the remove()/focus problem described above.
      The exception is occuring because focusRoot == focusOwner when focusNext() is
      called. Another problem I observed is that when focusOwner is null focusNext
      has no effect.

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

      test cases: start applet -> hit TAB key, it will generate NullPointerException

      code:

      -------------------------
      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      public class b516219
             extends Applet
             implements WindowListener, FocusListener
      {
          private Frame _mFrame1;
          private Dialog _mDialog1;
          private Button _mButton1;

          public b516219()
          {
          }

          public void start()
          {
              _mFrame1 = new Frame("Frame 1");
              _mFrame1.setBounds(100, 100, 300, 200);
              _mFrame1.setVisible(true);

              _mDialog1 = new Dialog(_mFrame1, "Dialog 1");
              _mDialog1.setBounds(150, 150, 300, 200);
              _mDialog1.setVisible(true);
              
              _mDialog1.addWindowListener(this);
              _mDialog1.addFocusListener(this);
          }

          public void windowOpened(WindowEvent e)
          {
          }

          public void windowClosing(WindowEvent e)
          {
          }

          public void windowClosed(WindowEvent e)
          {
          }

          public void windowIconified(WindowEvent e)
          {
          }

          public void windowDeiconified(WindowEvent e)
          {
          }

          public void windowActivated(WindowEvent e)
          {
              _mButton1 = new Button("Hello");
              _mDialog1.add(_mButton1);

              _mButton1.transferFocus();
          }

          public void windowDeactivated(WindowEvent e)
          {
          }

          public void focusGained(FocusEvent e)
          {
              _mButton1.setVisible(false);
          }

          public void focusLost(FocusEvent e)
          {
          }
      }
       

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: