Program: 145032
Project: 145032
Buggy source:
/** 
 * Evaluate the function call. First check if the function is a member of the built-in function suite. If not, then check for any custom handlers registered to handler the function. If not, throw and exception. Both function name and appropriate arguments are taken into account when finding a suitable handler. For built-in functions, the number of arguments must match; for custom functions, the supplied arguments must match one of the function prototypes defined by the handler.
 */
public Object eval(FormInstance model,EvaluationContext evalContext){
  String name=id.toString();
  Object[] argVals=new Object[args.length];
  Hashtable funcHandlers=evalContext.getFunctionHandlers();
  for (int i=0; i < args.length; i++) {
    argVals[i]=args[i].eval(model,evalContext);
  }
  if (name.equals("String_Node_Str") && args.length == 0) {
    return Boolean.TRUE;
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return Boolean.FALSE;
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toBoolean(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toNumeric(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toInt(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toString(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toDate(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return boolNot(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return boolStr(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return dateStr(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 3) {
    return ifThenElse(argVals[0],argVals[1],argVals[2]);
  }
 else   if ((name.equals("String_Node_Str") || name.equals("String_Node_Str")) && args.length == 2) {
    return multiSelected(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return countSelected(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return (!isNull(argVals[0]) ? argVals[0] : argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return count(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    if (argVals[0] instanceof XPathNodeset) {
      return sum(((XPathNodeset)argVals[0]).toArgList());
    }
 else {
      throw new XPathTypeMismatchException("String_Node_Str");
    }
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return DateUtils.roundDate(new Date());
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return new Date();
  }
 else   if (name.equals("String_Node_Str")) {
    if (args.length == 1 && argVals[0] instanceof XPathNodeset) {
      return join("String_Node_Str",((XPathNodeset)argVals[0]).toArgList());
    }
 else {
      return join("String_Node_Str",argVals);
    }
  }
 else   if (name.equals("String_Node_Str") && args.length >= 1) {
    if (args.length == 2 && argVals[1] instanceof XPathNodeset) {
      return join(argVals[0],((XPathNodeset)argVals[1]).toArgList());
    }
 else {
      return join(argVals[0],subsetArgList(argVals,1));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length >= 2) {
    if (args.length == 3 && argVals[2] instanceof XPathNodeset) {
      return checklist(argVals[0],argVals[1],((XPathNodeset)argVals[2]).toArgList());
    }
 else {
      return checklist(argVals[0],argVals[1],subsetArgList(argVals,2));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length >= 2 && args.length % 2 == 0) {
    if (args.length == 4 && argVals[2] instanceof XPathNodeset && argVals[3] instanceof XPathNodeset) {
      Object[] factors=((XPathNodeset)argVals[2]).toArgList();
      Object[] weights=((XPathNodeset)argVals[3]).toArgList();
      if (factors.length != weights.length) {
        throw new XPathTypeMismatchException("String_Node_Str");
      }
      return checklistWeighted(argVals[0],argVals[1],factors,weights);
    }
 else {
      return checklistWeighted(argVals[0],argVals[1],subsetArgList(argVals,2,2),subsetArgList(argVals,3,2));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return regex(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length >= 1) {
    return argVals[0];
  }
 else {
    IFunctionHandler handler=(IFunctionHandler)funcHandlers.get(name);
    if (handler != null) {
      return evalCustomFunction(handler,argVals);
    }
 else {
      throw new XPathUnhandledException("String_Node_Str" + name + "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * Evaluate the function call. First check if the function is a member of the built-in function suite. If not, then check for any custom handlers registered to handler the function. If not, throw and exception. Both function name and appropriate arguments are taken into account when finding a suitable handler. For built-in functions, the number of arguments must match; for custom functions, the supplied arguments must match one of the function prototypes defined by the handler.
 */
public Object eval(FormInstance model,EvaluationContext evalContext){
  String name=id.toString();
  Object[] argVals=new Object[args.length];
  Hashtable funcHandlers=evalContext.getFunctionHandlers();
  for (int i=0; i < args.length; i++) {
    argVals[i]=args[i].eval(model,evalContext);
  }
  if (name.equals("String_Node_Str") && args.length == 0) {
    return Boolean.TRUE;
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return Boolean.FALSE;
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toBoolean(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toNumeric(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toInt(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toString(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return toDate(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return boolNot(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return boolStr(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return dateStr(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 3) {
    return ifThenElse(argVals[0],argVals[1],argVals[2]);
  }
 else   if ((name.equals("String_Node_Str") || name.equals("String_Node_Str")) && args.length == 2) {
    return multiSelected(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return countSelected(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return (!isNull(argVals[0]) ? argVals[0] : argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return count(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    if (argVals[0] instanceof XPathNodeset) {
      return sum(((XPathNodeset)argVals[0]).toArgList());
    }
 else {
      throw new XPathTypeMismatchException("String_Node_Str");
    }
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return DateUtils.roundDate(new Date());
  }
 else   if (name.equals("String_Node_Str") && args.length == 0) {
    return new Date();
  }
 else   if (name.equals("String_Node_Str")) {
    if (args.length == 1 && argVals[0] instanceof XPathNodeset) {
      return join("String_Node_Str",((XPathNodeset)argVals[0]).toArgList());
    }
 else {
      return join("String_Node_Str",argVals);
    }
  }
 else   if (name.equals("String_Node_Str") && args.length >= 1) {
    if (args.length == 2 && argVals[1] instanceof XPathNodeset) {
      return join(argVals[0],((XPathNodeset)argVals[1]).toArgList());
    }
 else {
      return join(argVals[0],subsetArgList(argVals,1));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length == 1) {
    return stringLength(argVals[0]);
  }
 else   if (name.equals("String_Node_Str") && args.length >= 2) {
    if (args.length == 3 && argVals[2] instanceof XPathNodeset) {
      return checklist(argVals[0],argVals[1],((XPathNodeset)argVals[2]).toArgList());
    }
 else {
      return checklist(argVals[0],argVals[1],subsetArgList(argVals,2));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length >= 2 && args.length % 2 == 0) {
    if (args.length == 4 && argVals[2] instanceof XPathNodeset && argVals[3] instanceof XPathNodeset) {
      Object[] factors=((XPathNodeset)argVals[2]).toArgList();
      Object[] weights=((XPathNodeset)argVals[3]).toArgList();
      if (factors.length != weights.length) {
        throw new XPathTypeMismatchException("String_Node_Str");
      }
      return checklistWeighted(argVals[0],argVals[1],factors,weights);
    }
 else {
      return checklistWeighted(argVals[0],argVals[1],subsetArgList(argVals,2,2),subsetArgList(argVals,3,2));
    }
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    return regex(argVals[0],argVals[1]);
  }
 else   if (name.equals("String_Node_Str") && args.length >= 1) {
    return argVals[0];
  }
 else {
    IFunctionHandler handler=(IFunctionHandler)funcHandlers.get(name);
    if (handler != null) {
      return evalCustomFunction(handler,argVals);
    }
 else {
      throw new XPathUnhandledException("String_Node_Str" + name + "String_Node_Str");
    }
  }
}