AbstractPainter extends AbstractBean implements Painter<T> { @Override public final void paint(Graphics2D g, T obj, int width, int height) { if (g == null) { throw new NullPointerException("The Graphics2D must be supplied"); } if(!isVisible() || width < 1 || height < 1) { return; } configureGraphics(g); if (shouldUseCache() || filters.length > 0) { validate(obj); BufferedImage cache = cachedImage == null ? null : cachedImage.get(); boolean invalidCache = null == cache || cache.getWidth() != width || cache.getHeight() != height; if (cacheCleared || invalidCache || isDirty()) { if (invalidCache) { cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height); } Graphics2D gfx = cache.createGraphics(); try { gfx.setClip(0, 0, width, height); if (!invalidCache) { Composite composite = gfx.getComposite(); gfx.setComposite(AlphaComposite.Clear); gfx.fillRect(0, 0, width, height); gfx.setComposite(composite); } configureGraphics(gfx); doPaint(gfx, obj, width, height); } finally { gfx.dispose(); } if (!isInPaintContext()) { for (BufferedImageOp f : getFilters()) { cache = f.filter(cache, null); } } if (shouldUseCache()) { cachedImage = new SoftReference<BufferedImage>(cache); cacheCleared = false; } } g.drawImage(cache, 0, 0, null); } else { doPaint(g, obj, width, height); } setDirty(false); } AbstractPainter();  AbstractPainter(boolean cacheable); final BufferedImageOp[] getFilters(); void setFilters(BufferedImageOp ... effects); boolean isAntialiasing(); void setAntialiasing(boolean value); Interpolation getInterpolation(); void setInterpolation(Interpolation value); boolean isVisible(); void setVisible(boolean visible); boolean isCacheable(); void setCacheable(boolean cacheable); void clearCache(); @Override final void paint(Graphics2D g, T obj, int width, int height);  }
@Test(expected=NullPointerException.class) public void testPaintWithNullGraphics() { p.paint(null, null, 10, 10); }