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

JComponent.safelyGetGraphics() may sometimes return null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • client-libs
    • b134
    • generic
    • generic
    • Verified

      The JComponent.safelyGetGraphics() is widely used in javax.swing to obtain the Graphics object for a component. This method uses the Component.getGraphics() to obtain one. The javadoc for getGraphics() states that this method may sometimes return null. However, Swing code never verifies the return value of this method, and therefore may throw NPE under some circumstances.

      One of the cases when this problem is observed is the test/closed/java/awt/Container/ZOrder/ tets. When ran with JDK7b18 (or later, and probably some older releases) it constantly throws NPE at the JComponent._paintImmediately() method when trying to do g.dispose(), and g is null (as previously returned by the safelyGetGraphics()).

            alexp Alexander Potochkin (Inactive)
            anthony Anthony Petrov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: