Program: 113520
Project: 113520
Buggy source:
@Override public void executeReset(FileCredentials credentials,final long updateObjVer,final long localFileSize,final long localTruncateEpoch,final ExecuteResetCallback callback){
  final String fileId=credentials.getXcap().getFile_id();
  final int numAcksRequired=getNumRequiredAcks(Operation.INTERNAL_UPDATE);
  final int numRequests=remoteOSDs.size();
  final int maxErrors=numRequests - numAcksRequired;
  System.out.println("String_Node_Str" + maxErrors + "String_Node_Str"+ numAcksRequired+ "String_Node_Str"+ numRequests);
  final RPCResponse[] responses=new RPCResponse[remoteOSDs.size()];
  for (int i=0; i < responses.length; i++) {
    responses[i]=client.rwr_status(remoteOSDs.get(i),credentials,credentials.getXcap().getFile_id(),this.localObjVersion);
  }
  RPCResponseAvailableListener listener=new RPCResponseAvailableListener(){
    int numResponses=0;
    int numErrors=0;
    boolean exceptionSent=false;
    ReplicaStatus[] states=new ReplicaStatus[numAcksRequired];
    @Override public void responseAvailable(    RPCResponse r){
      if (numResponses < numAcksRequired) {
        int osdNum=-1;
        for (int i=0; i < numRequests; i++) {
          if (responses[i] == r) {
            osdNum=i;
            break;
          }
        }
        assert(osdNum > -1);
        try {
          states[osdNum]=(ReplicaStatus)r.get();
          numResponses++;
        }
 catch (        Exception ex) {
          numErrors++;
          if (numErrors > maxErrors) {
            if (!exceptionSent) {
              exceptionSent=true;
              if (Logging.isDebug()) {
                Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId);
              }
              callback.failed(ex);
            }
          }
          return;
        }
 finally {
          r.freeBuffers();
        }
      }
      if (numResponses == numAcksRequired) {
        if (Logging.isDebug()) {
          Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId);
        }
        boolean needsReset=false;
        long maxObjVer=0;
        long maxFileSize=0;
        long maxTrEpoch=0;
        for (        ReplicaStatus state : states) {
          if (state.getMax_obj_version() > localObjVersion) {
            needsReset=true;
            maxObjVer=state.getMax_obj_version();
            maxFileSize=state.getFile_size();
            maxTrEpoch=state.getTruncate_epoch();
            break;
          }
        }
        if (needsReset) {
          Map<Long,ObjectFetchRecord> recs=new HashMap();
          LinkedList<ObjectFetchRecord> order=new LinkedList<ObjectFetchRecord>();
          if ((localTruncateEpoch < maxTrEpoch) && (localFileSize > maxFileSize)) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId,localTruncateEpoch,maxTrEpoch);
            }
            order.add(new ObjectFetchRecord(maxFileSize,maxTrEpoch));
          }
          for (int i=0; i < numAcksRequired; i++) {
            final ReplicaStatus state=states[i];
            for (            ObjectVersion over : state.getObjectVersions()) {
              if ((updateObjVer > -1) && (over.getObject_version() >= updateObjVer))               continue;
              ObjectFetchRecord ofr=recs.get(over.getObject_number());
              if (ofr == null) {
                List<InetSocketAddress> osds=new ArrayList(numAcksRequired);
                osds.add(getRemoteOSDs().get(i));
                ofr=new ObjectFetchRecord(over.getObject_number(),over.getObject_version(),osds);
                recs.put(over.getObject_number(),ofr);
                order.add(ofr);
              }
 else {
                if (ofr.getObjVersion() < over.getObject_version()) {
                  ofr.setObjVersion(over.getObject_version());
                  ofr.getOsds().clear();
                  ofr.getOsds().add(getRemoteOSDs().get(i));
                }
 else                 if (ofr.getObjVersion() == over.getObject_version()) {
                  ofr.getOsds().add(getRemoteOSDs().get(i));
                }
              }
            }
          }
          Collections.sort(order,new Comparator<ObjectFetchRecord>(){
            @Override public int compare(            ObjectFetchRecord o1,            ObjectFetchRecord o2){
              if (o1.isTruncate())               return -1;
              int verCmp=(int)(o1.getObjVersion() - o2.getObjVersion());
              if (verCmp == 0) {
                return (int)(o2.getObjNumber() - o2.getObjNumber());
              }
 else               return verCmp;
            }
          }
);
          callback.finished(order);
        }
 else {
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId,maxObjVer);
          }
          callback.finished(null);
        }
      }
    }
  }
;
  for (int i=0; i < responses.length; i++) {
    responses[i].registerListener(listener);
  }
  if (Logging.isDebug())   Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + cellId);
}

Fixed version (ground truth):
@Override public void executeReset(FileCredentials credentials,final long updateObjVer,final long localFileSize,final long localTruncateEpoch,final ExecuteResetCallback callback){
  final String fileId=credentials.getXcap().getFile_id();
  final int numAcksRequired=getNumRequiredAcks(Operation.INTERNAL_UPDATE);
  final int numRequests=remoteOSDs.size();
  final int maxErrors=numRequests - numAcksRequired;
  final RPCResponse[] responses=new RPCResponse[remoteOSDs.size()];
  for (int i=0; i < responses.length; i++) {
    responses[i]=client.rwr_status(remoteOSDs.get(i),credentials,credentials.getXcap().getFile_id(),this.localObjVersion);
  }
  RPCResponseAvailableListener listener=new RPCResponseAvailableListener(){
    int numResponses=0;
    int numErrors=0;
    boolean exceptionSent=false;
    ReplicaStatus[] states=new ReplicaStatus[numAcksRequired];
    @Override public void responseAvailable(    RPCResponse r){
      if (numResponses < numAcksRequired) {
        int osdNum=-1;
        for (int i=0; i < numRequests; i++) {
          if (responses[i] == r) {
            osdNum=i;
            break;
          }
        }
        assert(osdNum > -1);
        try {
          states[osdNum]=(ReplicaStatus)r.get();
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",osdNum,states[osdNum]);
          }
          numResponses++;
        }
 catch (        Exception ex) {
          numErrors++;
          if (numErrors > maxErrors) {
            if (!exceptionSent) {
              exceptionSent=true;
              if (Logging.isDebug()) {
                Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId);
              }
              callback.failed(ex);
            }
          }
          return;
        }
 finally {
          r.freeBuffers();
        }
      }
      if (numResponses == numAcksRequired) {
        if (Logging.isDebug()) {
          Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId);
        }
        boolean needsReset=false;
        long maxObjVer=0;
        long maxFileSize=0;
        long maxTrEpoch=0;
        for (        ReplicaStatus state : states) {
          if (state.getMax_obj_version() > localObjVersion) {
            needsReset=true;
            maxObjVer=state.getMax_obj_version();
            maxFileSize=state.getFile_size();
            maxTrEpoch=state.getTruncate_epoch();
            break;
          }
        }
        if (needsReset) {
          Map<Long,ObjectFetchRecord> recs=new HashMap();
          LinkedList<ObjectFetchRecord> order=new LinkedList<ObjectFetchRecord>();
          if ((localTruncateEpoch < maxTrEpoch) && (localFileSize > maxFileSize)) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId,localTruncateEpoch,maxTrEpoch);
            }
            order.add(new ObjectFetchRecord(maxFileSize,maxTrEpoch));
          }
          for (int i=0; i < numAcksRequired; i++) {
            final ReplicaStatus state=states[i];
            for (            ObjectVersion over : state.getObjectVersions()) {
              if ((updateObjVer > -1) && (over.getObject_version() >= updateObjVer))               continue;
              ObjectFetchRecord ofr=recs.get(over.getObject_number());
              if (ofr == null) {
                List<InetSocketAddress> osds=new ArrayList(numAcksRequired);
                osds.add(getRemoteOSDs().get(i));
                ofr=new ObjectFetchRecord(over.getObject_number(),over.getObject_version(),osds);
                recs.put(over.getObject_number(),ofr);
                order.add(ofr);
              }
 else {
                if (ofr.getObjVersion() < over.getObject_version()) {
                  ofr.setObjVersion(over.getObject_version());
                  ofr.getOsds().clear();
                  ofr.getOsds().add(getRemoteOSDs().get(i));
                }
 else                 if (ofr.getObjVersion() == over.getObject_version()) {
                  ofr.getOsds().add(getRemoteOSDs().get(i));
                }
              }
            }
          }
          Collections.sort(order,new Comparator<ObjectFetchRecord>(){
            @Override public int compare(            ObjectFetchRecord o1,            ObjectFetchRecord o2){
              if (o1.isTruncate())               return -1;
              int verCmp=(int)(o1.getObjVersion() - o2.getObjVersion());
              if (verCmp == 0) {
                return (int)(o2.getObjNumber() - o2.getObjNumber());
              }
 else               return verCmp;
            }
          }
);
          callback.finished(order);
        }
 else {
          if (Logging.isDebug()) {
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str",fileId,maxObjVer);
          }
          callback.finished(null);
        }
      }
    }
  }
;
  for (int i=0; i < responses.length; i++) {
    responses[i].registerListener(listener);
  }
  if (Logging.isDebug())   Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + cellId);
}