Program: 71628
Project: 71628
Buggy source:
public IDataRowExpressionEvaluator prepareRowExpressionEvaluator(Chart cm,List columnExpression,int rowCount,boolean isStringType) throws ChartException {
  ClassLoader oldContextLoader=Thread.currentThread().getContextClassLoader();
  ClassLoader parentLoader=oldContextLoader;
  if (parentLoader == null)   parentLoader=this.getClass().getClassLoader();
  ClassLoader newContextLoader=DataSetProvider.getCustomScriptClassLoader(parentLoader,itemHandle.getModuleHandle());
  Thread.currentThread().setContextClassLoader(newContextLoader);
  IDataRowExpressionEvaluator evaluator=null;
  DataRequestSession session=null;
  ReportEngine engine=null;
  DummyEngineTask engineTask=null;
  try {
    if (isReportDesignHandle()) {
      engine=(ReportEngine)new ReportEngineFactory().createReportEngine(new EngineConfig());
      engineTask=new DummyEngineTask(engine,new ReportEngineHelper(engine).openReportDesign((ReportDesignHandle)itemHandle.getModuleHandle()));
    }
    CubeHandle cube=ChartXTabUtil.getBindingCube(itemHandle);
    if (cube != null) {
      if (isReportDesignHandle()) {
        session=prepareDataRequestSession(engineTask,getMaxRow(),true);
        engineTask.run();
      }
 else {
        session=prepareDataRequestSession(getMaxRow(),true);
      }
      evaluator=createCubeEvaluator(cube,session,engineTask);
    }
 else {
      if (isReportDesignHandle()) {
        session=prepareDataRequestSession(engineTask,getMaxRow(),false);
        engineTask.run();
      }
 else {
        session=prepareDataRequestSession(getMaxRow(),false);
      }
      if (isSharedBinding()) {
        evaluator=fShareBindingQueryHelper.createShareBindingEvaluator(cm,session,engineTask);
      }
 else {
        evaluator=createBaseEvaluator(itemHandle,cm,columnExpression,session,engineTask);
      }
    }
    return evaluator;
  }
 catch (  BirtException e) {
    if (engine == null && session != null) {
      session.shutdown();
    }
    if (engineTask != null) {
      engineTask.close();
    }
    throw new ChartException(ChartReportItemUIActivator.ID,ChartException.DATA_BINDING,e);
  }
catch (  RuntimeException e) {
    if (engine == null && session != null) {
      session.shutdown();
    }
    if (engineTask != null) {
      engineTask.close();
    }
    throw new ChartException(ChartReportItemUIActivator.ID,ChartException.DATA_BINDING,e);
  }
 finally {
    if (engine != null) {
      engine.destroy();
    }
    Thread.currentThread().setContextClassLoader(oldContextLoader);
  }
}

Fixed version (ground truth):
public IDataRowExpressionEvaluator prepareRowExpressionEvaluator(Chart cm,List columnExpression,int rowCount,boolean isStringType) throws ChartException {
  ClassLoader oldContextLoader=Thread.currentThread().getContextClassLoader();
  ClassLoader parentLoader=oldContextLoader;
  if (parentLoader == null)   parentLoader=this.getClass().getClassLoader();
  ClassLoader newContextLoader=DataSetProvider.getCustomScriptClassLoader(parentLoader,itemHandle.getModuleHandle());
  Thread.currentThread().setContextClassLoader(newContextLoader);
  IDataRowExpressionEvaluator evaluator=null;
  DataRequestSession session=null;
  ReportEngine engine=null;
  DummyEngineTask engineTask=null;
  try {
    if (isReportDesignHandle()) {
      engine=(ReportEngine)new ReportEngineFactory().createReportEngine(new EngineConfig());
      engineTask=new DummyEngineTask(engine,new ReportEngineHelper(engine).openReportDesign((ReportDesignHandle)itemHandle.getModuleHandle()),itemHandle.getModuleHandle());
    }
    CubeHandle cube=ChartXTabUtil.getBindingCube(itemHandle);
    if (cube != null) {
      if (isReportDesignHandle()) {
        session=prepareDataRequestSession(engineTask,getMaxRow(),true);
        engineTask.run();
      }
 else {
        session=prepareDataRequestSession(getMaxRow(),true);
      }
      evaluator=createCubeEvaluator(cube,session,engineTask);
    }
 else {
      if (isReportDesignHandle()) {
        session=prepareDataRequestSession(engineTask,getMaxRow(),false);
        engineTask.run();
      }
 else {
        session=prepareDataRequestSession(getMaxRow(),false);
      }
      if (isSharedBinding()) {
        evaluator=fShareBindingQueryHelper.createShareBindingEvaluator(cm,session,engineTask);
      }
 else {
        evaluator=createBaseEvaluator(itemHandle,cm,columnExpression,session,engineTask);
      }
    }
    return evaluator;
  }
 catch (  BirtException e) {
    if (engine == null && session != null) {
      session.shutdown();
    }
    if (engineTask != null) {
      engineTask.close();
    }
    throw new ChartException(ChartReportItemUIActivator.ID,ChartException.DATA_BINDING,e);
  }
catch (  RuntimeException e) {
    if (engine == null && session != null) {
      session.shutdown();
    }
    if (engineTask != null) {
      engineTask.close();
    }
    throw new ChartException(ChartReportItemUIActivator.ID,ChartException.DATA_BINDING,e);
  }
 finally {
    if (engine != null) {
      engine.destroy();
    }
    Thread.currentThread().setContextClassLoader(oldContextLoader);
  }
}