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

NullPointerException at java.awt.Component.findUnderMouseInWindow(Component.java:1001)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 6
    • client-libs
    • None
    • generic
    • generic

      Container.getMousePosition() asks for MouseInfo.getPointerInfo()
      When that returns null, PointerInfo pi == null and that cause NPE at Component.findUnderMouseInWindow(Component.java:1001)

      java.lang.NullPointerException
              at java.awt.Component.findUnderMouseInWindow(Component.java:1001)
              at java.awt.Container.getMousePosition(Container.java:2346)
              at org.netbeans.modules.debugger.jpda.ui.debugging.ClickableIcon.changeThread(ClickableIcon.java:115)
              at org.netbeans.modules.debugger.jpda.ui.debugging.DebuggingView$IconsPanel.addIcon(DebuggingView.java:928)
              at org.netbeans.modules.debugger.jpda.ui.debugging.DebuggingView$ViewRefresher.addPanels(DebuggingView.java:783)
              at org.netbeans.modules.debugger.jpda.ui.debugging.DebuggingView$ViewRefresher.run(DebuggingView.java:739)

      (See e.g.: http://www.netbeans.org/issues/show_bug.cgi?id=146185)
      Here is additional info and the test from awt-dev list:

      Attached is a test case that explains "The when and why the PointerInfo becomes null." The test case is a modified copy of the MouseInfo.getPointerInfo. To reproduce the error you need a workstation with multiple displays that are dependent. In my case a windows vista machine with 2 monitors. Run the test case and then lock the desktop of the workstation. When you log back in to the machine the test fails because the mouse point is not contained in any of the graphics configurations. This causes the PointerInfo to be null, and Component.getMousePosition does not handle this case.

      import org.junit.Test;
      import static org.junit.Assert.*;
      import java.awt.*;
      import java.awt.peer.*;
      import java.lang.reflect.*;

      /**
       * Run this test and lock your desktop.
       *
       * java.awt.Point[x=21680584,y=0] <------- not contained in and GC.
       * Win32GraphicsDevice[screen=0]
       * sun.awt.Win32GraphicsConfig@2e273686[dev=Win32GraphicsDevice[screen=0],pixfmt=0]
       * java.awt.Rectangle[x=0,y=0,width=1680,height=1050]
       * Win32GraphicsDevice[screen=1]
       * sun.awt.Win32GraphicsConfig@1ebcda2d[dev=Win32GraphicsDevice[screen=1],pixfmt=0]
       * java.awt.Rectangle[x=1680,y=0,width=1680,height=1050]
       * @author Jason Mehrens
       */
      public class Bug6840067 {

          private static final Method getPeer;
          private static final Method fillPoint;

          static {
              try {
                  getPeer = Toolkit.class.getDeclaredMethod("getMouseInfoPeer");
                  getPeer.setAccessible(true);

                  fillPoint = MouseInfoPeer.class.getDeclaredMethod("fillPointWithCoords", Point.class);
                  fillPoint.setAccessible(true);
              } catch (Exception e) {
                  throw new java.lang.ExceptionInInitializerError(e);
              }
          }

          public Bug6840067() {
          }

          /**
           * See java.awt.MouseInfo.getPointerInfo()
           * @throws Exception
           */
         @Test
          public void mouseTest() throws Exception {
              Point point = new Point(0, 0);
              GraphicsDevice[] gds = null;
              int deviceNum;
              while (true) {
                  boolean found = false;
                  Object peer = getPeer.invoke(Toolkit.getDefaultToolkit());
                  deviceNum = (Integer) fillPoint.invoke(peer, point);
                  gds = GraphicsEnvironment.getLocalGraphicsEnvironment().
                          getScreenDevices();
                  for (int i = 0; i < gds.length; i++) {
                      GraphicsConfiguration gc = gds[i].getDefaultConfiguration();
                      Rectangle bounds = gc.getBounds();
                      if (bounds.contains(point)) {
                          found = true;
                          break;
                      }
                  }

                  if (!found) { //this is not covered
                      break;
                  }
              }

              System.out.println(deviceNum);
              System.out.println(point);
              for (int i = 0; i < gds.length; i++) {
                  GraphicsConfiguration gc = gds[i].getDefaultConfiguration();
                  Rectangle bounds = gc.getBounds();
                  System.out.println(gds[i]);
                  System.out.println(gc);
                  System.out.println(bounds);
              }

              fail(point.toString());
          }
      }

            Unassigned Unassigned
            mentlich Martin Entlicher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: