Program: 56505
Project: 56505
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));
  }
  EvaluationResult result=null;
  try {
    NBook book=context.getBook();
    AbstractBookSeriesAdv bookSeries=(AbstractBookSeriesAdv)book.getBookSeries();
    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 (      NBook 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));
      }
      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);
    }
  }
 catch (  NotImplementedException e) {
    logger.log(Level.INFO,e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_NAME));
  }
catch (  FormulaParseException e) {
    logger.log(Level.SEVERE,e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
catch (  Exception e) {
    logger.log(Level.SEVERE,e.getMessage() + "String_Node_Str" + expr.getFormulaString(),e);
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
  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));
  }
  EvaluationResult result=null;
  try {
    NBook book=context.getBook();
    AbstractBookSeriesAdv bookSeries=(AbstractBookSeriesAdv)book.getBookSeries();
    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 (      NBook 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));
        NFunctionResolver resolver=NFunctionResolverFactory.getFunctionResolver();
        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);
    }
  }
 catch (  NotImplementedException e) {
    logger.log(Level.INFO,e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_NAME));
  }
catch (  FormulaParseException e) {
    logger.log(Level.SEVERE,e.getMessage() + "String_Node_Str" + expr.getFormulaString());
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
catch (  Exception e) {
    logger.log(Level.SEVERE,e.getMessage() + "String_Node_Str" + expr.getFormulaString(),e);
    result=new EvaluationResultImpl(ResultType.ERROR,new ErrorValue(ErrorValue.INVALID_FORMULA));
  }
  return result;
}