Program: 57171
Project: 57171
Buggy source:
public Optimum optimize(final LeastSquaresProblem lsp){
  final Incrementor evaluationCounter=lsp.getEvaluationCounter();
  final Incrementor iterationCounter=lsp.getIterationCounter();
  final ConvergenceChecker<Evaluation> checker=lsp.getConvergenceChecker();
  if (checker == null) {
    throw new NullArgumentException();
  }
  final int nR=lsp.getObservationSize();
  final int nC=lsp.getParameterSize();
  final RealVector currentPoint=lsp.getStart();
  Evaluation current=null;
  while (true) {
    iterationCounter.incrementCount();
    Evaluation previous=current;
    evaluationCounter.incrementCount();
    current=lsp.evaluate(currentPoint);
    final RealVector currentResiduals=current.computeResiduals();
    final RealMatrix weightedJacobian=current.computeJacobian();
    if (previous != null) {
      if (checker.converged(iterationCounter.getCount(),previous,current)) {
        return new OptimumImpl(current,evaluationCounter.getCount(),iterationCounter.getCount());
      }
    }
    final double[] b=new double[nC];
    final double[][] a=new double[nC][nC];
    for (int i=0; i < nR; ++i) {
      final double[] grad=weightedJacobian.getRow(i);
      final double residual=currentResiduals.getEntry(i);
      for (int j=0; j < nC; ++j) {
        b[j]+=residual * grad[j];
      }
      for (int k=0; k < nC; ++k) {
        double[] ak=a[k];
        for (int l=0; l < nC; ++l) {
          ak[l]+=grad[k] * grad[l];
        }
      }
    }
    try {
      RealMatrix mA=new BlockRealMatrix(a);
      DecompositionSolver solver=this.decomposition.getSolver(mA);
      final RealVector dX=solver.solve(new ArrayRealVector(b,false));
      for (int i=0; i < nC; ++i) {
        currentPoint.setEntry(i,currentPoint.getEntry(i) + dX.getEntry(i));
      }
    }
 catch (    SingularMatrixException e) {
      throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
    }
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public Optimum optimize(final LeastSquaresProblem lsp){
  final Incrementor evaluationCounter=lsp.getEvaluationCounter();
  final Incrementor iterationCounter=lsp.getIterationCounter();
  final ConvergenceChecker<Evaluation> checker=lsp.getConvergenceChecker();
  if (checker == null) {
    throw new NullArgumentException();
  }
  final int nR=lsp.getObservationSize();
  final int nC=lsp.getParameterSize();
  final RealVector currentPoint=lsp.getStart();
  Evaluation current=null;
  while (true) {
    iterationCounter.incrementCount();
    Evaluation previous=current;
    evaluationCounter.incrementCount();
    current=lsp.evaluate(currentPoint);
    final RealVector currentResiduals=current.computeResiduals();
    final RealMatrix weightedJacobian=current.computeJacobian();
    if (previous != null) {
      if (checker.converged(iterationCounter.getCount(),previous,current)) {
        return new OptimumImpl(current,evaluationCounter.getCount(),iterationCounter.getCount());
      }
    }
    final double[] b=new double[nC];
    final double[][] a=new double[nC][nC];
    for (int i=0; i < nR; ++i) {
      final double[] grad=weightedJacobian.getRow(i);
      final double residual=currentResiduals.getEntry(i);
      for (int j=0; j < nC; ++j) {
        b[j]+=residual * grad[j];
      }
      for (int k=0; k < nC; ++k) {
        double[] ak=a[k];
        for (int l=0; l < nC; ++l) {
          ak[l]+=grad[k] * grad[l];
        }
      }
    }
    try {
      RealMatrix mA=new BlockRealMatrix(a);
      DecompositionSolver solver=this.decomposition.getSolver(mA);
      final RealVector dX=solver.solve(new ArrayRealVector(b,false));
      for (int i=0; i < nC; ++i) {
        currentPoint.setEntry(i,currentPoint.getEntry(i) + dX.getEntry(i));
      }
    }
 catch (    SingularMatrixException e) {
      throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
    }
  }
}