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

NullPointerException: peer when application gets focus

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_161"
      Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When java application (see source code) gets focus, and user hits the enter key, the NullPointerException is raised without any line of my code.

      REGRESSION. Last worked in version 8u151

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Start program
      2) Focus any another window (for example any browser, MS Word or something else), so that no caret is displayed in the text field
      3) Go back to the program window
      4) Press the Enter key.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception is raised
      ACTUAL -
      Exception in console.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: peer
      at sun.awt.windows.WInputMethod.openCandidateWindow(Native Method)
      at sun.awt.windows.WInputMethod.access$400(WInputMethod.java:45)
      at sun.awt.windows.WInputMethod$1.run(WInputMethod.java:599)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:709)
      at java.awt.EventQueue$3.run(EventQueue.java:703)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
      at java.awt.EventQueue$4.run(EventQueue.java:731)
      at java.awt.EventQueue$4.run(EventQueue.java:729)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextField;
      import javax.swing.SwingUtilities;

      public class JumpBetweenTextFields {

          private static void createAndShowGUI() {
              JFrame frame = new JFrame("Jump between text fields");

              JPanel p = new JPanel(new FlowLayout());

              final JTextField firstField = new JTextField(5);
              final JTextField secondField = new JTextField(5);
              installAction(firstField, secondField);
              installAction(secondField, firstField);
              p.add(firstField);
              p.add(secondField);
              secondField.setEditable(false);

              frame.getContentPane().add(p);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(300, 300);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }

          private static void installAction(final JTextField t1, final JTextField t2) {
              t1.addActionListener(new ActionListener() {

                  @Override
                  public void actionPerformed(ActionEvent e) {
                      SwingUtilities.invokeLater(new Runnable() {
                          @Override
                          public void run() {
                              t1.setText("");
                              t1.setEditable(false);
                              t2.setEditable(true);
                              t2.requestFocus();
                          }
                      });
                  }
              });

          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Ignore this exception (we notify user about any non-catched exception in our application)

            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: