Program: 75537
Project: 75537
Buggy source:
/** 
 * Apply the specified function to the specified array and return an array with the results. The function must take at least one argument. If the function takes more than one argument, then the specified array should be an array of arrays, where each subarray is a set of arguments.  Since arrays in the expression language can only contain elements of the same type, this method will only work for functions whose arguments are all of the same type.
 * @param function A function with at least one argument.
 * @param array The array to which to apply the function.
 * @return A new array that is the result of applying the functionto the specified array.
 * @exception IllegalActionException If the specified function does nottake at least one argument, or if an error occurs applying the function, or if the number of arguments does not match the subarray lengths.
 */
public static ArrayToken map(FunctionToken function,ArrayToken array) throws IllegalActionException {
  int arity=function.getNumberOfArguments();
  Token[] result=new Token[array.length()];
  if (arity == 1) {
    for (int i=0; i < array.length(); i++) {
      Token args=(Token)array.getElement(i);
      LinkedList arglist=new LinkedList();
      arglist.add(args);
      result[i]=function.apply(arglist);
    }
  }
 else   if (arity > 1) {
    for (int i=0; i < array.length(); i++) {
      Token args=(Token)array.getElement(i);
      if (!(args instanceof ArrayToken)) {
        throw new IllegalActionException("String_Node_Str");
      }
      LinkedList arglist=new LinkedList();
      ArrayToken castArgs=(ArrayToken)args;
      if (castArgs.length() != arity) {
        throw new IllegalActionException("String_Node_Str");
      }
 else {
        for (int j=1; j < arity; j++) {
          arglist.add(castArgs.getElement(j));
        }
        result[i]=function.apply(arglist);
      }
    }
  }
 else {
    throw new IllegalActionException("String_Node_Str");
  }
  return new ArrayToken(result);
}

Fixed version (ground truth):
/** 
 * Apply the specified function to the specified array and return an array with the results. The function must take at least one argument. If the function takes more than one argument, then the specified array should be an array of arrays, where each subarray is a set of arguments.  Since arrays in the expression language can only contain elements of the same type, this method will only work for functions whose arguments are all of the same type.
 * @param function A function with at least one argument.
 * @param array The array to which to apply the function.
 * @return A new array that is the result of applying the functionto the specified array.
 * @exception IllegalActionException If the specified function does nottake at least one argument, or if an error occurs applying the function, or if the number of arguments does not match the subarray lengths.
 */
public static ArrayToken map(FunctionToken function,ArrayToken array) throws IllegalActionException {
  int arity=function.getNumberOfArguments();
  Token[] result=new Token[array.length()];
  if (arity == 1) {
    for (int i=0; i < array.length(); i++) {
      Token args=(Token)array.getElement(i);
      LinkedList arglist=new LinkedList();
      arglist.add(args);
      result[i]=function.apply(arglist);
    }
  }
 else   if (arity > 1) {
    for (int i=0; i < array.length(); i++) {
      Token args=(Token)array.getElement(i);
      if (!(args instanceof ArrayToken)) {
        throw new IllegalActionException("String_Node_Str");
      }
      LinkedList arglist=new LinkedList();
      ArrayToken castArgs=(ArrayToken)args;
      if (castArgs.length() != arity) {
        throw new IllegalActionException("String_Node_Str");
      }
 else {
        for (int j=0; j < arity; j++) {
          arglist.add(castArgs.getElement(j));
        }
        result[i]=function.apply(arglist);
      }
    }
  }
 else {
    throw new IllegalActionException("String_Node_Str");
  }
  return new ArrayToken(result);
}