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

getGraphics() throws NullPtrExc when component is NOT showing on win32

    XMLWordPrintable

Details

    • sparc
    • solaris_2.6

    Description

      When running the Java2D demo on win32 you may see this exception :

      java.lang.NullPointerException: component argument pData
              at sun.awt.windows.WGraphics.createFromComponent(Native Method)
              at sun.awt.windows.WGraphics.<init>(WGraphics.java:106)
              at sun.awt.windows.WComponentPeer.getGraphics(WComponentPeer.java:154)
              at java.awt.Component.getGraphics(Component.java:1487)
              at J2DCanvas.run(J2DCanvas.java:268)
              at java.lang.Thread.run(Thread.java:475)

      The animated demos fall out or stop if they are no longer showing :

      demo/jfc/Java2D/J2DCanvas.java
         257 public void run() {

         267 while (thread == me && isShowing()) {
         268 Graphics g = getGraphics();
         269 paint(g);
         270 g.dispose();
         271 try {
         272 Thread.sleep(sleepAmount);
         273 } catch (InterruptedException e) { return; }
         274 }
         275 thread = null;
         276 }

      So it seems that isShowing() returns false sometime when inside of the getGraphics() call. This problem does not appear on Solaris only on win32.

      To reproduce run several iterations of the demo. From the Options menu select the Run Window menuitem, select the run button.

      java full version "JDK-1.2beta4-K"


      =======
      The current demo has gone lightweight, using repaint() instead of getGraphics().
      To reproduce the bug, use the following test case:

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

      public class test extends JPanel {

          public test() { }

          public void getGraphics_() {
              Graphics g = getGraphics();
              System.out.println(isShowing() + " " + g);
          }

          public static void main(String argv[]) {
              test t = new test();
              t.getGraphics_();
              Frame f = new Frame("test");
              f.add("Center", t);
              f.pack();
              f.setSize(new Dimension(500,300));
              t.getGraphics_();
              f.show();
              t.getGraphics_();
          }
      }

      Attachments

        Activity

          People

            duke J. Duke
            blichtensunw Brian Lichtenwalter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: