Program: 80319
Project: 80319
Buggy source:
/** 
 * Wait for all workers done in current iteration.
 */
@Override public void preIteration(final MasterContext<MASTER_RESULT,WORKER_RESULT> context){
synchronized (LOCK) {
    this.currentInteration=context.getCurrentIteration();
    this.canUpdateWorkerResultMap=true;
  }
  long start=System.nanoTime();
  new RetryCoordinatorCommand(isFixedTime(),getSleepTime()){
    @Override public boolean retryExecution() throws KeeperException, InterruptedException {
      int doneWorkers;
synchronized (LOCK) {
        doneWorkers=(int)NettyMasterCoordinator.this.iterResults.size();
      }
      if (System.nanoTime() % 30 == 0) {
        LOG.info("String_Node_Str",context.getCurrentIteration(),doneWorkers,(context.getWorkers() - doneWorkers));
      }
      boolean isTerminated=false;
      if (context.isFirstIteration() || context.getCurrentIteration() == context.getTotalIteration()) {
        isTerminated=isTerminated(doneWorkers,context.getWorkers(),context.getMinWorkersRatio(),GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_TIMEOUT);
        if (isTerminated) {
synchronized (LOCK) {
            NettyMasterCoordinator.this.canUpdateWorkerResultMap=false;
          }
          LOG.info("String_Node_Str",context.getCurrentIteration(),context.getWorkers(),doneWorkers,GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_RATIO,GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_TIMEOUT);
        }
      }
 else {
        isTerminated=isTerminated(doneWorkers,context.getWorkers(),context.getMinWorkersRatio(),context.getMinWorkersTimeOut());
        if (isTerminated) {
synchronized (LOCK) {
            NettyMasterCoordinator.this.canUpdateWorkerResultMap=false;
          }
          LOG.info("String_Node_Str",context.getCurrentIteration(),context.getWorkers(),doneWorkers,context.getMinWorkersRatio(),context.getMinWorkersTimeOut());
        }
      }
      return isTerminated;
    }
  }
.execute();
synchronized (LOCK) {
    this.canUpdateWorkerResultMap=false;
    this.iterResults.switchState();
  }
  final int currentIter=this.currentInteration;
  context.setWorkerResults(new Iterable<WORKER_RESULT>(){
    @Override public Iterator<WORKER_RESULT> iterator(){
      return new Iterator<WORKER_RESULT>(){
        private Iterator<BytableWrapper> localItr;
        private volatile AtomicBoolean isStart=new AtomicBoolean();
        private boolean isPrint=false;
        BytableWrapper current=null;
        @Override public boolean hasNext(){
          boolean hasNext;
synchronized (LOCK) {
            if (!isPrint) {
              Iterator<BytableWrapper> ii=NettyMasterCoordinator.this.iterResults.iterator();
              int curr=0, notCurr=0;
              while (ii.hasNext()) {
                BytableWrapper next=ii.next();
                if (NettyMasterCoordinator.this.currentInteration == next.getCurrentIteration()) {
                  curr+=1;
                }
 else {
                  notCurr+=1;
                  LOG.info("String_Node_Str",next);
                }
              }
              LOG.info("String_Node_Str",curr,notCurr);
              isPrint=true;
            }
            if (this.isStart.compareAndSet(false,true)) {
              this.localItr=NettyMasterCoordinator.this.iterResults.iterator();
            }
            hasNext=this.localItr.hasNext();
            if (hasNext) {
              this.current=this.localItr.next();
              while (this.current.getCurrentIteration() != currentIter) {
                hasNext=this.localItr.hasNext();
                if (hasNext) {
                  this.current=this.localItr.next();
                  continue;
                }
 else {
                  break;
                }
              }
            }
            if (!hasNext) {
              this.localItr=NettyMasterCoordinator.this.iterResults.iterator();
              return false;
            }
          }
          return hasNext;
        }
        @Override public WORKER_RESULT next(){
synchronized (LOCK) {
            return NettyMasterCoordinator.this.getWorkerSerializer().bytesToObject(this.current.getBytes(),context.getWorkerResultClassName());
          }
        }
        @Override public void remove(){
          throw new UnsupportedOperationException();
        }
      }
;
    }
  }
);
  LOG.info("String_Node_Str",context.getAppId(),context.getContainerId(),context.getCurrentIteration(),TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
}

Fixed version (ground truth):
/** 
 * Wait for all workers done in current iteration.
 */
@Override public void preIteration(final MasterContext<MASTER_RESULT,WORKER_RESULT> context){
synchronized (LOCK) {
    this.currentInteration=context.getCurrentIteration();
    this.canUpdateWorkerResultMap=true;
  }
  long start=System.nanoTime();
  new RetryCoordinatorCommand(isFixedTime(),getSleepTime()){
    @Override public boolean retryExecution() throws KeeperException, InterruptedException {
      int doneWorkers;
synchronized (LOCK) {
        doneWorkers=(int)NettyMasterCoordinator.this.iterResults.size();
      }
      if (System.nanoTime() % 30 == 0) {
        LOG.info("String_Node_Str",context.getCurrentIteration(),doneWorkers,(context.getWorkers() - doneWorkers));
      }
      boolean isTerminated=false;
      if (context.isFirstIteration() || context.getCurrentIteration() == context.getTotalIteration()) {
        isTerminated=isTerminated(doneWorkers,context.getWorkers(),context.getMinWorkersRatio(),GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_TIMEOUT);
        if (isTerminated) {
synchronized (LOCK) {
            NettyMasterCoordinator.this.canUpdateWorkerResultMap=false;
          }
          LOG.info("String_Node_Str",context.getCurrentIteration(),context.getWorkers(),doneWorkers,context.getMinWorkersRatio(),GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_TIMEOUT);
        }
      }
 else {
        isTerminated=isTerminated(doneWorkers,context.getWorkers(),context.getMinWorkersRatio(),context.getMinWorkersTimeOut());
        if (isTerminated) {
synchronized (LOCK) {
            NettyMasterCoordinator.this.canUpdateWorkerResultMap=false;
          }
          LOG.info("String_Node_Str",context.getCurrentIteration(),context.getWorkers(),doneWorkers,context.getMinWorkersRatio(),context.getMinWorkersTimeOut());
        }
      }
      return isTerminated;
    }
  }
.execute();
synchronized (LOCK) {
    this.canUpdateWorkerResultMap=false;
    this.iterResults.switchState();
  }
  final int currentIter=this.currentInteration;
  context.setWorkerResults(new Iterable<WORKER_RESULT>(){
    @Override public Iterator<WORKER_RESULT> iterator(){
      return new Iterator<WORKER_RESULT>(){
        private Iterator<BytableWrapper> localItr;
        private volatile AtomicBoolean isStart=new AtomicBoolean();
        private boolean isPrint=false;
        BytableWrapper current=null;
        @Override public boolean hasNext(){
          boolean hasNext;
synchronized (LOCK) {
            if (!isPrint) {
              Iterator<BytableWrapper> ii=NettyMasterCoordinator.this.iterResults.iterator();
              int curr=0, notCurr=0;
              while (ii.hasNext()) {
                BytableWrapper next=ii.next();
                if (NettyMasterCoordinator.this.currentInteration == next.getCurrentIteration()) {
                  curr+=1;
                }
 else {
                  notCurr+=1;
                  LOG.info("String_Node_Str",next);
                }
              }
              LOG.info("String_Node_Str",curr,notCurr);
              isPrint=true;
            }
            if (this.isStart.compareAndSet(false,true)) {
              this.localItr=NettyMasterCoordinator.this.iterResults.iterator();
            }
            hasNext=this.localItr.hasNext();
            if (hasNext) {
              this.current=this.localItr.next();
              while (this.current.getCurrentIteration() != currentIter) {
                hasNext=this.localItr.hasNext();
                if (hasNext) {
                  this.current=this.localItr.next();
                  continue;
                }
 else {
                  break;
                }
              }
            }
            if (!hasNext) {
              this.localItr=NettyMasterCoordinator.this.iterResults.iterator();
              return false;
            }
          }
          return hasNext;
        }
        @Override public WORKER_RESULT next(){
synchronized (LOCK) {
            return NettyMasterCoordinator.this.getWorkerSerializer().bytesToObject(this.current.getBytes(),context.getWorkerResultClassName());
          }
        }
        @Override public void remove(){
          throw new UnsupportedOperationException();
        }
      }
;
    }
  }
);
  LOG.info("String_Node_Str",context.getAppId(),context.getContainerId(),context.getCurrentIteration(),TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
}