Program: 70944
Project: 70944
Buggy source:
/** 
 * Draws a previously built chart using the specified device renderer into a target output device.
 * @param idr A device renderer that determines the target context on which the chart will be rendered.
 * @param gcs A previously built chart that needs to be rendered.
 * @throws ChartException
 */
public final void render(IDeviceRenderer idr,GeneratedChartState gcs) throws ChartException {
  final Chart cm=gcs.getChartModel();
  idr.getDisplayServer().setResourceFinder(gcs.getRunTimeContext().getResourceFinder());
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.START_RENDERING,gcs);
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.BEFORE_RENDERING,gcs,gcs.getRunTimeContext().getScriptContext());
  Legend lg=cm.getLegend();
  lg.updateLayout(cm);
  if (lg.getPosition() == Position.INSIDE_LITERAL) {
    int iType=gcs.getType();
    if (iType == WITH_AXES) {
      Bounds bo=((PlotWithAxes)gcs.getComputations()).getPlotBounds();
      updateLegendInside(bo,lg,idr.getDisplayServer(),cm,gcs.getRunTimeContext());
    }
 else     if (iType == WITHOUT_AXES) {
      Bounds bo=((PlotWithoutAxes)gcs.getComputations()).getBounds();
      updateLegendInside(bo,lg,idr.getDisplayServer(),cm,gcs.getRunTimeContext());
    }
  }
  final LinkedHashMap lhm=gcs.getRenderers();
  final int iSize=lhm.size();
  BaseRenderer br;
  final Collection co=lhm.values();
  final LegendItemRenderingHints[] lirha=(LegendItemRenderingHints[])co.toArray(new LegendItemRenderingHints[co.size()]);
  final DeferredCacheManager dcm=new DeferredCacheManager(idr,cm);
  DeferredCache dc=null;
  final Bounds bo=gcs.getChartModel().getBlock().getBounds();
  idr.setProperty(IDeviceRenderer.EXPECTED_BOUNDS,bo.scaledInstance(idr.getDisplayServer().getDpiResolution() / 72d));
  gcs.getRunTimeContext().setStructureDefinitionListener(idr.needsStructureDefinition() ? idr : null);
  idr.before();
  for (int i=0; i < iSize; i++) {
    br=lirha[i].getRenderer();
    dc=dcm.createDeferredCache(br);
    br.setDeferredCacheManager(dcm);
    br.set(dc);
    br.set(idr);
    br.set(gcs.getRunTimeContext());
    try {
      br.render(lhm,bo);
    }
 catch (    RuntimeException ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,ex);
    }
  }
  idr.after();
  gcs.getRunTimeContext().clearState();
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.FINISH_RENDERING,gcs);
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.AFTER_RENDERING,gcs,gcs.getRunTimeContext().getScriptContext());
}

Fixed version (ground truth):
/** 
 * Draws a previously built chart using the specified device renderer into a target output device.
 * @param idr A device renderer that determines the target context on which the chart will be rendered.
 * @param gcs A previously built chart that needs to be rendered.
 * @throws ChartException
 */
public final void render(IDeviceRenderer idr,GeneratedChartState gcs) throws ChartException {
  final Chart cm=gcs.getChartModel();
  idr.getDisplayServer().setResourceFinder(gcs.getRunTimeContext().getResourceFinder());
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.START_RENDERING,gcs);
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.BEFORE_RENDERING,gcs,gcs.getRunTimeContext().getScriptContext());
  Legend lg=cm.getLegend();
  lg.updateLayout(cm);
  if (lg.getPosition() == Position.INSIDE_LITERAL) {
    int iType=gcs.getType();
    if (iType == WITH_AXES) {
      Bounds bo=((PlotWithAxes)gcs.getComputations()).getPlotBounds();
      updateLegendInside(bo,lg,idr.getDisplayServer(),cm,gcs.getRunTimeContext());
    }
 else     if (iType == WITHOUT_AXES) {
      Bounds bo=((PlotWithoutAxes)gcs.getComputations()).getBounds();
      updateLegendInside(bo,lg,idr.getDisplayServer(),cm,gcs.getRunTimeContext());
    }
  }
  final LinkedHashMap lhm=gcs.getRenderers();
  final int iSize=lhm.size();
  BaseRenderer br;
  final Collection co=lhm.values();
  final LegendItemRenderingHints[] lirha=(LegendItemRenderingHints[])co.toArray(new LegendItemRenderingHints[co.size()]);
  final DeferredCacheManager dcm=new DeferredCacheManager(idr,cm);
  DeferredCache dc=null;
  final Bounds bo=gcs.getChartModel().getBlock().getBounds();
  idr.setProperty(IDeviceRenderer.EXPECTED_BOUNDS,bo.scaledInstance(idr.getDisplayServer().getDpiResolution() / 72d));
  gcs.getRunTimeContext().setStructureDefinitionListener(idr.needsStructureDefinition() ? idr : null);
  idr.before();
  for (int i=0; i < iSize; i++) {
    br=lirha[i].getRenderer();
    dc=dcm.createDeferredCache(br);
    br.setDeferredCacheManager(dcm);
    br.set(dc);
    br.set(idr);
    br.set(gcs.getRunTimeContext());
    try {
      br.render(lhm,bo);
    }
 catch (    RuntimeException ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,ex);
    }
  }
  idr.after();
  if (needClearState(idr)) {
    gcs.getRunTimeContext().clearState();
  }
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.FINISH_RENDERING,gcs);
  ScriptHandler.callFunction(gcs.getRunTimeContext().getScriptHandler(),ScriptHandler.AFTER_RENDERING,gcs,gcs.getRunTimeContext().getScriptContext());
}