Program: 68374
Project: 68374
Buggy source:
public void after() throws ChartException {
  super.after();
  if (_oOutputIdentifier != null) {
    ImageWriter iw=ImageWriterFactory.instance().createByFormatName(getFormat());
    if (iw == null) {
      String s=getMimeType();
      if (s == null) {
        throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,"String_Node_Str",new Object[]{getMimeType(),getFormat(),getClass().getName()},Messages.getResourceBundle(getULocale()));
      }
      Iterator<ImageWriter> it=ImageIO.getImageWritersByMIMEType(s);
      if (!it.hasNext()) {
        throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,"String_Node_Str",new Object[]{getMimeType()},Messages.getResourceBundle(getULocale()));
      }
      iw=it.next();
    }
    logger.log(ILogger.INFORMATION,Messages.getString("String_Node_Str",getULocale()) + getFormat() + iw.getClass().getName());
    final Object o=(_oOutputIdentifier instanceof String) ? new File((String)_oOutputIdentifier) : _oOutputIdentifier;
    try {
      final ImageOutputStream ios=SecurityUtil.newImageOutputStream(o);
      updateWriterParameters(iw.getDefaultWriteParam());
      iw.setOutput(ios);
      iw.write((RenderedImage)_img);
      ios.close();
    }
 catch (    Exception ex) {
      throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,ex);
    }
 finally {
      iw.dispose();
    }
  }
  if (!_bImageExternallySpecified) {
    _img.flush();
    _img=null;
  }
  _g2d.dispose();
  _g2d=null;
}

Fixed version (ground truth):
public void after() throws ChartException {
  super.after();
  if (_oOutputIdentifier != null) {
    ImageWriter iw=ImageWriterFactory.instance().createByFormatName(getFormat());
    if (iw == null) {
      String s=getMimeType();
      if (s == null) {
        throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,"String_Node_Str",new Object[]{getMimeType(),getFormat(),getClass().getName()},Messages.getResourceBundle(getULocale()));
      }
      Iterator<ImageWriter> it=ImageIO.getImageWritersByMIMEType(s);
      if (!it.hasNext()) {
        throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,"String_Node_Str",new Object[]{getMimeType()},Messages.getResourceBundle(getULocale()));
      }
      iw=it.next();
    }
    logger.log(ILogger.INFORMATION,Messages.getString("String_Node_Str",getULocale()) + getFormat() + iw.getClass().getName());
    final Object o=(_oOutputIdentifier instanceof String) ? new File((String)_oOutputIdentifier) : _oOutputIdentifier;
    try {
      final ImageOutputStream ios=SecurityUtil.newImageOutputStream(o);
      ImageWriteParam iwp=iw.getDefaultWriteParam();
      updateWriterParameters(iwp);
      iw.setOutput(ios);
      iw.write((IIOMetadata)null,new IIOImage((BufferedImage)_img,null,null),iwp);
      ios.close();
    }
 catch (    Exception ex) {
      throw new ChartException(ChartDeviceExtensionPlugin.ID,ChartException.RENDERING,ex);
    }
 finally {
      iw.dispose();
    }
  }
  if (!_bImageExternallySpecified) {
    _img.flush();
    _img=null;
  }
  _g2d.dispose();
  _g2d=null;
}