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()).