Program: 144777
Project: 144777
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(DataInstance model,EvaluationContext evalContext){
  String name=id.toString();
  Object[] argVals=new Object[args.length];
  Hashtable funcHandlers=evalContext.getFunctionHandlers();
  if (name.equals("String_Node_Str") && args.length == 3) {
    return ifThenElse(model,evalContext,args,argVals);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    argVals[0]=XPathFuncExpr.unpack(args[0].eval(model,evalContext));
    if (!isNull(argVals[0])) {
      return argVals[0];
    }
 else {
      argVals[1]=args[1].eval(model,evalContext);
      return argVals[1];
    }
  }
  for (int i=0; i < args.length; i++) {
    argVals[i]=args[i].eval(model,evalContext);
  }
  try {
    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 toDouble(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") || 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 selectedAt(argVals[0],argVals[1]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 0 || args.length == 1)) {
      if (args.length == 1) {
        return position(((XPathNodeset)argVals[0]).getRefAt(0));
      }
 else {
        if (evalContext.getContextPosition() != -1) {
          return new Double(evalContext.getContextPosition());
        }
        return position(evalContext.getContextRef());
      }
    }
 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")) {
      if (argVals[0] instanceof XPathNodeset) {
        return max(((XPathNodeset)argVals[0]).toArgList());
      }
 else {
        return max(argVals);
      }
    }
 else     if (name.equals("String_Node_Str")) {
      if (argVals[0] instanceof XPathNodeset) {
        return min(((XPathNodeset)argVals[0]).toArgList());
      }
 else {
        return min(argVals);
      }
    }
 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 || args.length == 3)) {
      return substring(argVals[0],argVals[1],args.length == 3 ? argVals[2] : null);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return stringLength(argVals[0]);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return normalizeCase(argVals[0],true);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return normalizeCase(argVals[0],false);
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).indexOf(toString(argVals[1])) != -1;
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).startsWith(toString(argVals[1]));
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).endsWith(toString(argVals[1]));
    }
 else     if (name.equals("String_Node_Str") && args.length == 3) {
      return translate(argVals[0],argVals[1],argVals[2]);
    }
 else     if (name.equals("String_Node_Str") && args.length == 3) {
      return replace(argVals[0],argVals[1],argVals[2]);
    }
 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     if (name.equals("String_Node_Str") && args.length == 0) {
      return new Double(MathUtils.getRand().nextDouble());
    }
 else     if (name.equals("String_Node_Str") && (args.length == 0 || args.length == 1)) {
      if (args.length == 0) {
        return PropertyUtils.genUUID();
      }
      int len=toInt(argVals[0]).intValue();
      return PropertyUtils.genGUID(len);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 2)) {
      return power(argVals[0],argVals[1]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.abs(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.ceil(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.floor(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double((double)(Math.floor(toDouble(argVals[0]).doubleValue() + 0.5)));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return log(argVals[0]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return log10(argVals[0]);
    }
 else {
      IFunctionHandler handler=(IFunctionHandler)funcHandlers.get(name);
      if (handler != null) {
        return evalCustomFunction(handler,argVals,evalContext);
      }
 else {
        throw new XPathUnhandledException("String_Node_Str" + name + "String_Node_Str");
      }
    }
  }
 catch (  ClassCastException cce) {
    String args="String_Node_Str";
    for (int i=0; i < argVals.length; ++i) {
      args+="String_Node_Str" + String.valueOf(unpack(argVals[i])) + "String_Node_Str"+ (i == argVals.length - 1 ? "String_Node_Str" : "String_Node_Str");
    }
    throw new XPathException("String_Node_Str" + name + "String_Node_Str"+ args+ "String_Node_Str"+ "String_Node_Str"+ cce.getMessage());
  }
}

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(DataInstance model,EvaluationContext evalContext){
  String name=id.toString();
  Object[] argVals=new Object[args.length];
  Hashtable funcHandlers=evalContext.getFunctionHandlers();
  if (name.equals("String_Node_Str") && args.length == 3) {
    return ifThenElse(model,evalContext,args,argVals);
  }
 else   if (name.equals("String_Node_Str") && args.length == 2) {
    argVals[0]=XPathFuncExpr.unpack(args[0].eval(model,evalContext));
    if (!isNull(argVals[0])) {
      return argVals[0];
    }
 else {
      argVals[1]=args[1].eval(model,evalContext);
      return argVals[1];
    }
  }
  for (int i=0; i < args.length; i++) {
    argVals[i]=args[i].eval(model,evalContext);
  }
  try {
    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 toDouble(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") || 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 selectedAt(argVals[0],argVals[1]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 0 || args.length == 1)) {
      if (args.length == 1) {
        return position(((XPathNodeset)argVals[0]).getRefAt(0));
      }
 else {
        if (evalContext.getContextPosition() != -1) {
          return new Double(evalContext.getContextPosition());
        }
        return position(evalContext.getContextRef());
      }
    }
 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.length == 1 && argVals[0] instanceof XPathNodeset) {
        return sum(((XPathNodeset)argVals[0]).toArgList());
      }
 else {
        throw new XPathTypeMismatchException("String_Node_Str");
      }
    }
 else     if (name.equals("String_Node_Str")) {
      if (argVals.length == 1 && argVals[0] instanceof XPathNodeset) {
        return max(((XPathNodeset)argVals[0]).toArgList());
      }
 else {
        return max(argVals);
      }
    }
 else     if (name.equals("String_Node_Str")) {
      if (argVals.length == 1 && argVals[0] instanceof XPathNodeset) {
        return min(((XPathNodeset)argVals[0]).toArgList());
      }
 else {
        return min(argVals);
      }
    }
 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 || args.length == 3)) {
      return substring(argVals[0],argVals[1],args.length == 3 ? argVals[2] : null);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return stringLength(argVals[0]);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return normalizeCase(argVals[0],true);
    }
 else     if (name.equals("String_Node_Str") && args.length == 1) {
      return normalizeCase(argVals[0],false);
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).indexOf(toString(argVals[1])) != -1;
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).startsWith(toString(argVals[1]));
    }
 else     if (name.equals("String_Node_Str") && args.length == 2) {
      return toString(argVals[0]).endsWith(toString(argVals[1]));
    }
 else     if (name.equals("String_Node_Str") && args.length == 3) {
      return translate(argVals[0],argVals[1],argVals[2]);
    }
 else     if (name.equals("String_Node_Str") && args.length == 3) {
      return replace(argVals[0],argVals[1],argVals[2]);
    }
 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     if (name.equals("String_Node_Str") && args.length == 0) {
      return new Double(MathUtils.getRand().nextDouble());
    }
 else     if (name.equals("String_Node_Str") && (args.length == 0 || args.length == 1)) {
      if (args.length == 0) {
        return PropertyUtils.genUUID();
      }
      int len=toInt(argVals[0]).intValue();
      return PropertyUtils.genGUID(len);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 2)) {
      return power(argVals[0],argVals[1]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.abs(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.ceil(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double(Math.floor(toDouble(argVals[0]).doubleValue()));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return new Double((double)(Math.floor(toDouble(argVals[0]).doubleValue() + 0.5)));
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return log(argVals[0]);
    }
 else     if (name.equals("String_Node_Str") && (args.length == 1)) {
      return log10(argVals[0]);
    }
 else {
      IFunctionHandler handler=(IFunctionHandler)funcHandlers.get(name);
      if (handler != null) {
        return evalCustomFunction(handler,argVals,evalContext);
      }
 else {
        throw new XPathUnhandledException("String_Node_Str" + name + "String_Node_Str");
      }
    }
  }
 catch (  ClassCastException cce) {
    String args="String_Node_Str";
    for (int i=0; i < argVals.length; ++i) {
      args+="String_Node_Str" + String.valueOf(unpack(argVals[i])) + "String_Node_Str"+ (i == argVals.length - 1 ? "String_Node_Str" : "String_Node_Str");
    }
    throw new XPathException("String_Node_Str" + name + "String_Node_Str"+ args+ "String_Node_Str"+ "String_Node_Str"+ cce.getMessage());
  }
}