Program: 161664
Project: 161664
Buggy source:
/** 
 * Counts how many futures provided completed with a result that matches the one provided here.   This can be most useful if your looking to know if an error occurred that was not an   {@link ExecutionException}.  For example assume an API return's   {@code Future<Boolean>} and a {@code false} represents a failure, this can be used to look for those types of error results.   Just like  {@link #blockTillAllComplete(Iterable)}, this will block until all futures have  completed (so we can verify if their result matches or not).
 * @since 4.0.0
 * @param < T > type of result futures provide to compare against
 * @param futures Structure of futures to iterate over
 * @param comparisonResult Object to compare future results against to look for match
 * @param timeoutInMillis timeout to wait for futures to complete in milliseconds
 * @return Number of futures which match the result using a {@link Object#equals(Object)} comparison
 * @throws InterruptedException Thrown if thread is interrupted while waiting on future's result
 * @throws TimeoutException Thrown if the timeout elapsed while waiting on futures to complete
 */
public static <T>int countFuturesWithResult(Iterable<? extends Future<?>> futures,T comparisonResult,long timeoutInMillis) throws InterruptedException, TimeoutException {
  if (futures == null) {
    return 0;
  }
  int resultCount=0;
  Iterator<? extends Future<?>> it=futures.iterator();
  long startTime=Clock.accurateForwardProgressingMillis();
  long remainingTime;
  while (it.hasNext() && (remainingTime=timeoutInMillis - (Clock.lastKnownForwardProgressingMillis() - startTime)) > 0) {
    Future<?> f=it.next();
    try {
      if (comparisonResult == null && f.get(remainingTime,TimeUnit.MILLISECONDS) == null) {
        resultCount++;
      }
 else       if (comparisonResult.equals(f.get(remainingTime,TimeUnit.MILLISECONDS))) {
        resultCount++;
      }
    }
 catch (    CancellationException e) {
    }
catch (    ExecutionException e) {
    }
  }
  if (it.hasNext()) {
    throw new TimeoutException();
  }
  return resultCount;
}

Fixed version (ground truth):
/** 
 * Counts how many futures provided completed with a result that matches the one provided here.   This can be most useful if your looking to know if an error occurred that was not an   {@link ExecutionException}.  For example assume an API return's   {@code Future<Boolean>} and a {@code false} represents a failure, this can be used to look for those types of error results.   Just like  {@link #blockTillAllComplete(Iterable)}, this will block until all futures have  completed (so we can verify if their result matches or not).
 * @since 4.0.0
 * @param < T > type of result futures provide to compare against
 * @param futures Structure of futures to iterate over
 * @param comparisonResult Object to compare future results against to look for match
 * @param timeoutInMillis timeout to wait for futures to complete in milliseconds
 * @return Number of futures which match the result using a {@link Object#equals(Object)} comparison
 * @throws InterruptedException Thrown if thread is interrupted while waiting on future's result
 * @throws TimeoutException Thrown if the timeout elapsed while waiting on futures to complete
 */
public static <T>int countFuturesWithResult(Iterable<? extends Future<?>> futures,T comparisonResult,long timeoutInMillis) throws InterruptedException, TimeoutException {
  if (futures == null) {
    return 0;
  }
  int resultCount=0;
  Iterator<? extends Future<?>> it=futures.iterator();
  long startTime=Clock.accurateForwardProgressingMillis();
  long remainingTime;
  while (it.hasNext() && (remainingTime=timeoutInMillis - (Clock.lastKnownForwardProgressingMillis() - startTime)) > 0) {
    Future<?> f=it.next();
    try {
      if (comparisonResult == null) {
        if (f.get(remainingTime,TimeUnit.MILLISECONDS) == null) {
          resultCount++;
        }
      }
 else       if (comparisonResult.equals(f.get(remainingTime,TimeUnit.MILLISECONDS))) {
        resultCount++;
      }
    }
 catch (    CancellationException e) {
    }
catch (    ExecutionException e) {
    }
  }
  if (it.hasNext()) {
    throw new TimeoutException();
  }
  return resultCount;
}