Program: 56461
Project: 56461
Buggy source:
@Override @SuppressWarnings("String_Node_Str") public EvaluationResult evaluate(FormulaExpression expr,FormulaEvaluationContext context){
  if (expr.hasError()) {
    return new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
  Ref dependant=context.getDependent();
  EvaluationResult result=null;
  try {
    SBook book=context.getBook();
    AbstractBookSeriesAdv bookSeries=(AbstractBookSeriesAdv)book.getBookSeries();
    DependencyTableAdv table=(DependencyTableAdv)bookSeries.getDependencyTable();
    Map<String,EvalContext> evalCtxMap=(Map<String,EvalContext>)bookSeries.getAttribute(KEY_EVALUATORS);
    if (evalCtxMap == null) {
      evalCtxMap=new LinkedHashMap<String,FormulaEngineImpl.EvalContext>();
      List<String> bookNames=new ArrayList<String>();
      List<WorkbookEvaluator> evaluators=new ArrayList<WorkbookEvaluator>();
      for (      SBook nb : bookSeries.getBooks()) {
        String bookName=nb.getBookName();
        EvalBook evalBook=new EvalBook(nb);
        WorkbookEvaluator we=new WorkbookEvaluator(evalBook,noCacheClassifier,null);
        bookNames.add(bookName);
        evaluators.add(we);
        evalCtxMap.put(bookName,new EvalContext(evalBook,we));
        FunctionResolver resolver=FunctionResolverFactory.createFunctionResolver();
        UDFFinder zkUDFF=resolver.getUDFFinder();
        if (zkUDFF != null) {
          IndexedUDFFinder bookUDFF=(IndexedUDFFinder)evalBook.getUDFFinder();
          bookUDFF.insert(0,zkUDFF);
        }
      }
      CollaboratingWorkbooksEnvironment.setup(bookNames.toArray(new String[0]),evaluators.toArray(new WorkbookEvaluator[0]));
      bookSeries.setAttribute(KEY_EVALUATORS,evalCtxMap);
    }
    EvalContext ctx=evalCtxMap.get(book.getBookName());
    if (ctx == null) {
      throw new IllegalStateException("String_Node_Str");
    }
    EvalBook evalBook=ctx.getBook();
    WorkbookEvaluator evaluator=ctx.getEvaluator();
    Object oldXelCtx=getXelContext();
    XelContext xelCtx=getXelContextForResolving(context,evalBook,evaluator);
    setXelContext(xelCtx);
    try {
      result=evaluateFormula(expr,context,evalBook,evaluator);
    }
  finally {
      setXelContext(oldXelCtx);
    }
    if (dependant != null) {
      table.setEvaluated(dependant);
    }
  }
 catch (  NotImplementedException e) {
    _logger.info(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_NAME,e.getMessage()));
  }
catch (  EvaluationException e) {
    _logger.warning(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    ErrorEval error=e.getErrorEval();
    result=new EvaluationResultImpl(ResultType.ERROR,error == null ? new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()) : error);
  }
catch (  FormulaParseException e) {
    _logger.error(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()));
  }
catch (  Exception e) {
    _logger.error(e.getMessage() + "String_Node_Str" + expr.getFormulaString(),e);
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()));
  }
  return result;
}

Fixed version (ground truth):
@Override @SuppressWarnings("String_Node_Str") public EvaluationResult evaluate(FormulaExpression expr,FormulaEvaluationContext context){
  if (expr.hasError()) {
    return new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
  Ref dependant=context.getDependent();
  EvaluationResult result=null;
  try {
    SBook book=context.getBook();
    AbstractBookSeriesAdv bookSeries=(AbstractBookSeriesAdv)book.getBookSeries();
    DependencyTableAdv table=(DependencyTableAdv)bookSeries.getDependencyTable();
    NonSerializableHolder<Map<String,EvalContext>> holder=(NonSerializableHolder<Map<String,EvalContext>>)bookSeries.getAttribute(KEY_EVALUATORS);
    Map<String,EvalContext> evalCtxMap=holder == null ? null : holder.getObject();
    if (evalCtxMap == null) {
      evalCtxMap=new LinkedHashMap<String,FormulaEngineImpl.EvalContext>();
      List<String> bookNames=new ArrayList<String>();
      List<WorkbookEvaluator> evaluators=new ArrayList<WorkbookEvaluator>();
      for (      SBook nb : bookSeries.getBooks()) {
        String bookName=nb.getBookName();
        EvalBook evalBook=new EvalBook(nb);
        WorkbookEvaluator we=new WorkbookEvaluator(evalBook,noCacheClassifier,null);
        bookNames.add(bookName);
        evaluators.add(we);
        evalCtxMap.put(bookName,new EvalContext(evalBook,we));
        FunctionResolver resolver=FunctionResolverFactory.createFunctionResolver();
        UDFFinder zkUDFF=resolver.getUDFFinder();
        if (zkUDFF != null) {
          IndexedUDFFinder bookUDFF=(IndexedUDFFinder)evalBook.getUDFFinder();
          bookUDFF.insert(0,zkUDFF);
        }
      }
      CollaboratingWorkbooksEnvironment.setup(bookNames.toArray(new String[0]),evaluators.toArray(new WorkbookEvaluator[0]));
      bookSeries.setAttribute(KEY_EVALUATORS,new NonSerializableHolder<Map<String,EvalContext>>(evalCtxMap));
    }
    EvalContext ctx=evalCtxMap.get(book.getBookName());
    if (ctx == null) {
      throw new IllegalStateException("String_Node_Str");
    }
    EvalBook evalBook=ctx.getBook();
    WorkbookEvaluator evaluator=ctx.getEvaluator();
    Object oldXelCtx=getXelContext();
    XelContext xelCtx=getXelContextForResolving(context,evalBook,evaluator);
    setXelContext(xelCtx);
    try {
      result=evaluateFormula(expr,context,evalBook,evaluator);
    }
  finally {
      setXelContext(oldXelCtx);
    }
    if (dependant != null) {
      table.setEvaluated(dependant);
    }
  }
 catch (  NotImplementedException e) {
    _logger.info(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_NAME,e.getMessage()));
  }
catch (  EvaluationException e) {
    _logger.warning(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    ErrorEval error=e.getErrorEval();
    result=new EvaluationResultImpl(ResultType.ERROR,error == null ? new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()) : error);
  }
catch (  FormulaParseException e) {
    _logger.error(e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()));
  }
catch (  Exception e) {
    _logger.error(e.getMessage() + "String_Node_Str" + expr.getFormulaString(),e);
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA,e.getMessage()));
  }
  return result;
}