Program: 70016
Project: 70016
Buggy source:
/** 
 * Builds and computes preferred sizes of various chart components offscreen using the provided display server.
 * @param ids A display server using which the chart may be built.
 * @param cmDesignTime The design time chart model (bound to a dataset).
 * @param externalContext An external context object.
 * @param bo The bounds associated with the chart being built.
 * @param rtc Encapsulates the runtime environment for the build process.
 * @param externalProcessor An external style processor. If it's null, an implicit processor will be used.
 * @return An instance of a generated chart state that encapsulates builtchart information that may be subsequently rendered.
 * @throws ChartException
 */
public final GeneratedChartState build(IDisplayServer ids,Chart cmDesignTime,Bounds bo,IExternalContext externalContext,RunTimeContext rtc,IStyleProcessor externalProcessor) throws ChartException {
  if (ids == null || cmDesignTime == null || bo == null) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle());
  }
  if (rtc == null) {
    rtc=new RunTimeContext();
  }
  rtc.putState(StateKey.CHART_COMPUTATION_KEY,ChartComputationFactory.instance().createChartComputation());
  if (rtc.getULocale() == null) {
    rtc.setULocale(ULocale.getDefault());
  }
  IChartScriptContext icsc=rtc.getScriptContext();
  if (icsc == null) {
    ChartScriptContext csc=new ChartScriptContext();
    Chart cmRunTime=cmDesignTime.copyInstance();
    csc.setChartInstance(cmRunTime);
    csc.setExternalContext(externalContext);
    csc.setULocale(rtc.getULocale());
    csc.setLogger(logger);
    rtc.setScriptContext(csc);
    icsc=csc;
  }
 else   if (icsc instanceof ChartScriptContext) {
    ((ChartScriptContext)icsc).setLogger(logger);
    Chart cmRuntime=cmDesignTime.copyInstance();
    cmRuntime.getBlock().setBounds(bo);
    ((ChartScriptContext)icsc).setChartInstance(cmRuntime);
  }
  if (externalContext != null && icsc instanceof ChartScriptContext) {
    ((ChartScriptContext)icsc).setExternalContext(externalContext);
  }
  final Chart cmRunTime=icsc.getChartInstance();
  ScriptHandler sh=rtc.getScriptHandler();
  if (sh == null) {
    sh=new ScriptHandler();
    rtc.setScriptHandler(sh);
    sh.setScriptClassLoader(rtc.getScriptClassLoader());
    sh.setScriptContext(icsc);
    final String sScriptContent=cmRunTime.getScript();
    if (externalContext != null && externalContext.getScriptable() != null) {
      sh.init(externalContext.getScriptable());
    }
 else {
      sh.init(null);
    }
    sh.setRunTimeModel(cmRunTime);
    if (sScriptContent != null && sScriptContent.length() > 0 && rtc.isScriptingEnabled()) {
      sh.register(null,sScriptContent);
    }
  }
  ScriptHandler.callFunction(sh,ScriptHandler.START_GENERATION,cmRunTime);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_GENERATION,cmRunTime,rtc.getScriptContext());
  ChartUtil.pruneInvisibleSeries(cmRunTime);
  prepareStyles(cmRunTime,externalProcessor);
  PlotComputation oComputations=null;
  if (cmRunTime instanceof ChartWithAxes) {
    try {
      if (cmRunTime.getDimension() == ChartDimension.THREE_DIMENSIONAL_LITERAL) {
        oComputations=new PlotWith3DAxes(ids,(ChartWithAxes)cmRunTime,rtc);
      }
 else {
        oComputations=new PlotWith2DAxes(ids,(ChartWithAxes)cmRunTime,rtc);
      }
    }
 catch (    Exception e) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,e);
    }
  }
 else   if (cmRunTime instanceof ChartWithoutAxes) {
    oComputations=new PlotWithoutAxes(ids,(ChartWithoutAxes)cmRunTime,rtc);
  }
  if (oComputations == null) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",new Object[]{cmRunTime},Messages.getResourceBundle(rtc.getULocale()));
  }
  final LinkedHashMap<Series,LegendItemRenderingHints> lhmRenderers=new LinkedHashMap<Series,LegendItemRenderingHints>();
  BaseRenderer[] brna=null;
  try {
    brna=BaseRenderer.instances(cmRunTime,rtc,oComputations);
    for (int i=0; i < brna.length; i++) {
      lhmRenderers.put(brna[i].getSeries(),new LegendItemRenderingHints(brna[i],goFactory.createBounds(0,0,0,0)));
    }
    rtc.setSeriesRenderers(lhmRenderers);
    rtc.setLegendLayoutHints(null);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  if (oComputations instanceof PlotWith2DAxes) {
    PlotWith2DAxes pwa=(PlotWith2DAxes)oComputations;
    pwa.initDynamicPlotBounds(bo);
  }
  Block bl=cmRunTime.getBlock();
  final LayoutManager lm=new LayoutManager(bl);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_LAYOUT,cmRunTime);
  lm.doLayout(ids,cmRunTime,bo,rtc);
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_LAYOUT,cmRunTime);
  Bounds boPlot=cmRunTime.getPlot().getBounds();
  Insets insPlot=cmRunTime.getPlot().getInsets();
  boPlot=goFactory.adjusteBounds(boPlot,insPlot);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_COMPUTATIONS,cmRunTime,oComputations);
  try {
    oComputations.compute(boPlot);
  }
 catch (  Exception ex) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_COMPUTATIONS,cmRunTime,oComputations);
  final Collection<LegendItemRenderingHints> co=lhmRenderers.values();
  final LegendItemRenderingHints[] lirha=co.toArray(new LegendItemRenderingHints[co.size()]);
  final int iSize=lhmRenderers.size();
  BaseRenderer br;
  for (int i=0; i < iSize; i++) {
    br=lirha[i].getRenderer();
    br.set(brna);
    br.set(ids);
    br.set(rtc);
    try {
      br.set(br.getComputations().getSeriesRenderingHints(br.getSeriesDefinition(),br.getSeries()));
      ScriptHandler.callFunction(sh,ScriptHandler.START_COMPUTE_SERIES,br.getSeries());
      br.compute(bo,cmRunTime.getPlot(),br.getSeriesRenderingHints());
      ScriptHandler.callFunction(sh,ScriptHandler.FINISH_COMPUTE_SERIES,br.getSeries());
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
  final GeneratedChartState gcs=new GeneratedChartState(ids,cmRunTime,lhmRenderers,rtc,oComputations);
  if (sh != null) {
    sh.setGeneratedChartState(gcs);
    ScriptHandler.callFunction(sh,ScriptHandler.FINISH_GENERATION,gcs);
    ScriptHandler.callFunction(sh,ScriptHandler.AFTER_GENERATION,gcs,rtc.getScriptContext());
  }
  return gcs;
}

Fixed version (ground truth):
/** 
 * Builds and computes preferred sizes of various chart components offscreen using the provided display server.
 * @param ids A display server using which the chart may be built.
 * @param cmDesignTime The design time chart model (bound to a dataset).
 * @param externalContext An external context object.
 * @param bo The bounds associated with the chart being built.
 * @param rtc Encapsulates the runtime environment for the build process.
 * @param externalProcessor An external style processor. If it's null, an implicit processor will be used.
 * @return An instance of a generated chart state that encapsulates builtchart information that may be subsequently rendered.
 * @throws ChartException
 */
public final GeneratedChartState build(IDisplayServer ids,Chart cmDesignTime,Bounds bo,IExternalContext externalContext,RunTimeContext rtc,IStyleProcessor externalProcessor) throws ChartException {
  if (ids == null || cmDesignTime == null || bo == null) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle());
  }
  if (rtc == null) {
    rtc=new RunTimeContext();
  }
  rtc.putState(StateKey.CHART_COMPUTATION_KEY,ChartComputationFactory.instance().createChartComputation());
  if (rtc.getULocale() == null) {
    rtc.setULocale(ULocale.getDefault());
  }
  IChartScriptContext icsc=rtc.getScriptContext();
  if (icsc == null) {
    ChartScriptContext csc=new ChartScriptContext();
    Chart cmRunTime=cmDesignTime.copyInstance();
    csc.setChartInstance(cmRunTime);
    csc.setExternalContext(externalContext);
    csc.setULocale(rtc.getULocale());
    csc.setLogger(logger);
    rtc.setScriptContext(csc);
    icsc=csc;
  }
 else   if (icsc instanceof ChartScriptContext) {
    ((ChartScriptContext)icsc).setLogger(logger);
    Chart cmRuntime=cmDesignTime.copyInstance();
    cmRuntime.getBlock().setBounds(bo);
    ((ChartScriptContext)icsc).setChartInstance(cmRuntime);
  }
  if (externalContext != null && icsc instanceof ChartScriptContext) {
    ((ChartScriptContext)icsc).setExternalContext(externalContext);
  }
  final Chart cmRunTime=icsc.getChartInstance();
  ScriptHandler sh=rtc.getScriptHandler();
  if (sh == null) {
    sh=new ScriptHandler();
    rtc.setScriptHandler(sh);
    sh.setScriptClassLoader(rtc.getScriptClassLoader());
    sh.setScriptContext(icsc);
    final String sScriptContent=cmRunTime.getScript();
    if (externalContext != null && externalContext.getScriptable() != null) {
      sh.init(externalContext.getScriptable());
    }
 else {
      sh.init(null);
    }
    sh.setRunTimeModel(cmRunTime);
    if (sScriptContent != null && sScriptContent.length() > 0 && rtc.isScriptingEnabled()) {
      sh.register(null,sScriptContent);
    }
  }
  ScriptHandler.callFunction(sh,ScriptHandler.START_GENERATION,cmRunTime);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_GENERATION,cmRunTime,rtc.getScriptContext());
  ChartUtil.pruneInvisibleSeries(cmRunTime);
  checkDataEmpty(cmRunTime,rtc);
  prepareStyles(cmRunTime,externalProcessor);
  PlotComputation oComputations=null;
  if (cmRunTime instanceof ChartWithAxes) {
    try {
      if (cmRunTime.getDimension() == ChartDimension.THREE_DIMENSIONAL_LITERAL) {
        oComputations=new PlotWith3DAxes(ids,(ChartWithAxes)cmRunTime,rtc);
      }
 else {
        oComputations=new PlotWith2DAxes(ids,(ChartWithAxes)cmRunTime,rtc);
      }
    }
 catch (    Exception e) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,e);
    }
  }
 else   if (cmRunTime instanceof ChartWithoutAxes) {
    oComputations=new PlotWithoutAxes(ids,(ChartWithoutAxes)cmRunTime,rtc);
  }
  if (oComputations == null) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",new Object[]{cmRunTime},Messages.getResourceBundle(rtc.getULocale()));
  }
  final LinkedHashMap<Series,LegendItemRenderingHints> lhmRenderers=new LinkedHashMap<Series,LegendItemRenderingHints>();
  BaseRenderer[] brna=null;
  try {
    brna=BaseRenderer.instances(cmRunTime,rtc,oComputations);
    for (int i=0; i < brna.length; i++) {
      lhmRenderers.put(brna[i].getSeries(),new LegendItemRenderingHints(brna[i],goFactory.createBounds(0,0,0,0)));
    }
    rtc.setSeriesRenderers(lhmRenderers);
    rtc.setLegendLayoutHints(null);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  if (oComputations instanceof PlotWith2DAxes) {
    PlotWith2DAxes pwa=(PlotWith2DAxes)oComputations;
    pwa.initDynamicPlotBounds(bo);
  }
  Block bl=cmRunTime.getBlock();
  final LayoutManager lm=new LayoutManager(bl);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_LAYOUT,cmRunTime);
  lm.doLayout(ids,cmRunTime,bo,rtc);
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_LAYOUT,cmRunTime);
  Bounds boPlot=cmRunTime.getPlot().getBounds();
  Insets insPlot=cmRunTime.getPlot().getInsets();
  boPlot=goFactory.adjusteBounds(boPlot,insPlot);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_COMPUTATIONS,cmRunTime,oComputations);
  try {
    oComputations.compute(boPlot);
  }
 catch (  Exception ex) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_COMPUTATIONS,cmRunTime,oComputations);
  final Collection<LegendItemRenderingHints> co=lhmRenderers.values();
  final LegendItemRenderingHints[] lirha=co.toArray(new LegendItemRenderingHints[co.size()]);
  final int iSize=lhmRenderers.size();
  BaseRenderer br;
  for (int i=0; i < iSize; i++) {
    br=lirha[i].getRenderer();
    br.set(brna);
    br.set(ids);
    br.set(rtc);
    try {
      br.set(br.getComputations().getSeriesRenderingHints(br.getSeriesDefinition(),br.getSeries()));
      ScriptHandler.callFunction(sh,ScriptHandler.START_COMPUTE_SERIES,br.getSeries());
      br.compute(bo,cmRunTime.getPlot(),br.getSeriesRenderingHints());
      ScriptHandler.callFunction(sh,ScriptHandler.FINISH_COMPUTE_SERIES,br.getSeries());
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
  final GeneratedChartState gcs=new GeneratedChartState(ids,cmRunTime,lhmRenderers,rtc,oComputations);
  if (sh != null) {
    sh.setGeneratedChartState(gcs);
    ScriptHandler.callFunction(sh,ScriptHandler.FINISH_GENERATION,gcs);
    ScriptHandler.callFunction(sh,ScriptHandler.AFTER_GENERATION,gcs,rtc.getScriptContext());
  }
  return gcs;
}