Program: 57442
Project: 57442
Buggy source:
/** 
 * This method attempts to find two values a and b satisfying <ul> <li> <code> lowerBound <= a < initial < b <= upperBound</code> </li> <li> <code> f(a) * f(b) < 0 </code> </li> </ul> If f is continuous on <code>[a,b],</code> this means that <code>a</code> and <code>b</code> bracket a root of f. <p> The algorithm starts by setting  <code>a := initial -1; b := initial +1,</code> examines the value of the function at <code>a</code> and <code>b</code> and keeps moving the endpoints out by one unit each time through a loop that terminates  when one of the following happens: <ul> <li> <code> f(a) * f(b) < 0 </code> --  success!</li> <li> <code> a = lower </code> and <code> b = upper</code>  -- ConvergenceException </li> <li> <code> maximumIterations</code> iterations elapse  -- ConvergenceException </li></ul></p>
 * @param function the function
 * @param initial initial midpoint of interval being expanded tobracket a root
 * @param lowerBound lower bound (a is never lower than this value)
 * @param upperBound upper bound (b never is greater than thisvalue)
 * @param maximumIterations maximum number of iterations to perform
 * @return a two element array holding {a, b}.
 * @throws ConvergenceException if the algorithm fails to find a and bsatisfying the desired conditions
 * @throws FunctionEvaluationException if an error occurs evaluating the function
 * @throws IllegalArgumentException if function is null, maximumIterationsis not positive, or initial is not between lowerBound and upperBound
 */
public static double[] bracket(UnivariateRealFunction function,double initial,double lowerBound,double upperBound,int maximumIterations) throws ConvergenceException, FunctionEvaluationException {
  if (function == null) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str");
  }
  if (maximumIterations <= 0) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str",maximumIterations);
  }
  if (initial < lowerBound || initial > upperBound || lowerBound >= upperBound) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str",lowerBound,initial,upperBound);
  }
  double a=initial;
  double b=initial;
  double fa;
  double fb;
  int numIterations=0;
  do {
    a=Math.max(a - 1.0,lowerBound);
    b=Math.min(b + 1.0,upperBound);
    fa=function.value(a);
    fb=function.value(b);
    numIterations++;
  }
 while ((fa * fb > 0.0) && (numIterations < maximumIterations) && ((a > lowerBound) || (b < upperBound)));
  if (fa * fb >= 0.0) {
    throw new ConvergenceException("String_Node_Str" + "String_Node_Str" + "String_Node_Str",numIterations,maximumIterations,initial,lowerBound,upperBound,a,b,fa,fb);
  }
  return new double[]{a,b};
}

Fixed version (ground truth):
/** 
 * This method attempts to find two values a and b satisfying <ul> <li> <code> lowerBound <= a < initial < b <= upperBound</code> </li> <li> <code> f(a) * f(b) <= 0 </code> </li> </ul> If f is continuous on <code>[a,b],</code> this means that <code>a</code> and <code>b</code> bracket a root of f. <p> The algorithm starts by setting  <code>a := initial -1; b := initial +1,</code> examines the value of the function at <code>a</code> and <code>b</code> and keeps moving the endpoints out by one unit each time through a loop that terminates  when one of the following happens: <ul> <li> <code> f(a) * f(b) <= 0 </code> --  success!</li> <li> <code> a = lower </code> and <code> b = upper</code>  -- ConvergenceException </li> <li> <code> maximumIterations</code> iterations elapse  -- ConvergenceException </li></ul></p>
 * @param function the function
 * @param initial initial midpoint of interval being expanded tobracket a root
 * @param lowerBound lower bound (a is never lower than this value)
 * @param upperBound upper bound (b never is greater than thisvalue)
 * @param maximumIterations maximum number of iterations to perform
 * @return a two element array holding {a, b}.
 * @throws ConvergenceException if the algorithm fails to find a and bsatisfying the desired conditions
 * @throws FunctionEvaluationException if an error occurs evaluating the function
 * @throws IllegalArgumentException if function is null, maximumIterationsis not positive, or initial is not between lowerBound and upperBound
 */
public static double[] bracket(UnivariateRealFunction function,double initial,double lowerBound,double upperBound,int maximumIterations) throws ConvergenceException, FunctionEvaluationException {
  if (function == null) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str");
  }
  if (maximumIterations <= 0) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str",maximumIterations);
  }
  if (initial < lowerBound || initial > upperBound || lowerBound >= upperBound) {
    throw MathRuntimeException.createIllegalArgumentException("String_Node_Str",lowerBound,initial,upperBound);
  }
  double a=initial;
  double b=initial;
  double fa;
  double fb;
  int numIterations=0;
  do {
    a=Math.max(a - 1.0,lowerBound);
    b=Math.min(b + 1.0,upperBound);
    fa=function.value(a);
    fb=function.value(b);
    numIterations++;
  }
 while ((fa * fb > 0.0) && (numIterations < maximumIterations) && ((a > lowerBound) || (b < upperBound)));
  if (fa * fb > 0.0) {
    throw new ConvergenceException("String_Node_Str" + "String_Node_Str" + "String_Node_Str",numIterations,maximumIterations,initial,lowerBound,upperBound,a,b,fa,fb);
  }
  return new double[]{a,b};
}