Program: 72149
Project: 72149
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();
  }
  if (rtc.getULocale() == null) {
    rtc.setULocale(ULocale.getDefault());
  }
  IChartScriptContext icsc=rtc.getScriptContext();
  if (icsc == null) {
    ChartScriptContext csc=new ChartScriptContext();
    Chart cmRunTime=(Chart)EcoreUtil.copy(cmDesignTime);
    ChartUtil.pruneInvisibleSeries(cmRunTime);
    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=(Chart)EcoreUtil.copy(cmDesignTime);
    ChartUtil.pruneInvisibleSeries(cmRuntime);
    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());
  prepareStyles(cmRunTime,externalProcessor);
  int iChartType=UNDEFINED;
  Object oComputations=null;
  if (cmRunTime instanceof ChartWithAxes) {
    iChartType=WITH_AXES;
    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) {
    iChartType=WITHOUT_AXES;
    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 lhmRenderers=new LinkedHashMap();
  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],BoundsImpl.create(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=boPlot.adjustedInstance(insPlot);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_COMPUTATIONS,cmRunTime,oComputations);
  long lTimer=System.currentTimeMillis();
  if (iChartType == WITH_AXES) {
    PlotWithAxes pwa=(PlotWithAxes)oComputations;
    try {
      pwa.compute(boPlot);
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
 else   if (iChartType == WITHOUT_AXES) {
    PlotWithoutAxes pwoa=(PlotWithoutAxes)oComputations;
    try {
      pwoa.compute(boPlot);
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_COMPUTATIONS,cmRunTime,oComputations);
  final Collection co=lhmRenderers.values();
  final LegendItemRenderingHints[] lirha=(LegendItemRenderingHints[])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 {
      if (br.getComputations() instanceof PlotWithoutAxes) {
        br.set(((PlotWithoutAxes)br.getComputations()).getSeriesRenderingHints(br.getSeries()));
      }
 else {
        br.set(((PlotWithAxes)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);
    }
  }
  logger.log(ILogger.INFORMATION,Messages.getString("String_Node_Str",new Object[]{new Long(System.currentTimeMillis() - lTimer)},rtc.getULocale()));
  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();
  }
  if (rtc.getULocale() == null) {
    rtc.setULocale(ULocale.getDefault());
  }
  IChartScriptContext icsc=rtc.getScriptContext();
  if (icsc == null) {
    ChartScriptContext csc=new ChartScriptContext();
    Chart cmRunTime=(Chart)EcoreUtil.copy(cmDesignTime);
    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=(Chart)EcoreUtil.copy(cmDesignTime);
    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());
  prepareStyles(cmRunTime,externalProcessor);
  int iChartType=UNDEFINED;
  Object oComputations=null;
  if (cmRunTime instanceof ChartWithAxes) {
    iChartType=WITH_AXES;
    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) {
    iChartType=WITHOUT_AXES;
    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 lhmRenderers=new LinkedHashMap();
  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],BoundsImpl.create(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=boPlot.adjustedInstance(insPlot);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_COMPUTATIONS,cmRunTime,oComputations);
  long lTimer=System.currentTimeMillis();
  if (iChartType == WITH_AXES) {
    PlotWithAxes pwa=(PlotWithAxes)oComputations;
    try {
      pwa.compute(boPlot);
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
 else   if (iChartType == WITHOUT_AXES) {
    PlotWithoutAxes pwoa=(PlotWithoutAxes)oComputations;
    try {
      pwoa.compute(boPlot);
    }
 catch (    Exception ex) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
    }
  }
  ScriptHandler.callFunction(sh,ScriptHandler.AFTER_COMPUTATIONS,cmRunTime,oComputations);
  final Collection co=lhmRenderers.values();
  final LegendItemRenderingHints[] lirha=(LegendItemRenderingHints[])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 {
      if (br.getComputations() instanceof PlotWithoutAxes) {
        br.set(((PlotWithoutAxes)br.getComputations()).getSeriesRenderingHints(br.getSeries()));
      }
 else {
        br.set(((PlotWithAxes)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);
    }
  }
  logger.log(ILogger.INFORMATION,Messages.getString("String_Node_Str",new Object[]{new Long(System.currentTimeMillis() - lTimer)},rtc.getULocale()));
  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;
}