Program: 35193
Project: 35193
Buggy source:
/** 
 * Generic smget operation for b+tree items. Public smget methods call this method.
 * @param smGetList  smget parameters (keys, eflags, and so on)
 * @param offset  start index of the elements
 * @param count  number of elements to fetch
 * @param reverse  forward or backward
 * @param tc  transcoder to serialize and unserialize element value
 * @return future holding the smget result (elements, return codes, and so on)
 */
private <T>SMGetFuture<List<SMGetElement<T>>> smget(final List<BTreeSMGet<T>> smGetList,final int offset,final int count,final boolean reverse,final Transcoder<T> tc){
  final String END="String_Node_Str";
  final String TRIMMED="String_Node_Str";
  final String DUPLICATED="String_Node_Str";
  final String DUPLICATED_TRIMMED="String_Node_Str";
  final CountDownLatch blatch=new CountDownLatch(smGetList.size());
  final ConcurrentLinkedQueue<Operation> ops=new ConcurrentLinkedQueue<Operation>();
  final List<String> missedKey=Collections.synchronizedList(new ArrayList<String>());
  final int totalResultElementCount=count + offset;
  final List<SMGetElement<T>> mergedResult=Collections.synchronizedList(new ArrayList<SMGetElement<T>>(totalResultElementCount));
  final ReentrantLock lock=new ReentrantLock();
  final List<OperationStatus> resultOperationStatus=Collections.synchronizedList(new ArrayList<OperationStatus>(1));
  final List<OperationStatus> failedOperationStatus=Collections.synchronizedList(new ArrayList<OperationStatus>(1));
  final Set<Object> totalBkey=new TreeSet<Object>();
  final AtomicBoolean stopCollect=new AtomicBoolean(false);
  for (  BTreeSMGet<T> smGet : smGetList) {
    Operation op=opFact.bopsmget(smGet,new BTreeSortMergeGetOperation.Callback(){
      final List<SMGetElement<T>> eachResult=new ArrayList<SMGetElement<T>>();
      private void addTotalBkey(      List<SMGetElement<T>> smgetresult){
        for (        SMGetElement<T> each : smgetresult) {
          if (each.getBkeyByObject() instanceof byte[]) {
            totalBkey.add(new ByteArrayBKey((byte[])each.getBkeyByObject()));
          }
 else {
            totalBkey.add(each.getBkeyByObject());
          }
        }
      }
      private boolean addTotalBkey(      Object bkey){
        if (bkey instanceof byte[]) {
          return totalBkey.add(new ByteArrayBKey((byte[])bkey));
        }
 else {
          return totalBkey.add(bkey);
        }
      }
      @Override public void receivedStatus(      OperationStatus status){
        if (status.isSuccess()) {
          resultOperationStatus.add(status);
        }
 else {
          stopCollect.set(true);
          mergedResult.clear();
          failedOperationStatus.add(status);
        }
        if (status.isSuccess()) {
          lock.lock();
          try {
            if (smGetList.size() == 1) {
              addTotalBkey(eachResult);
              mergedResult.addAll(eachResult);
            }
 else {
              if (mergedResult.size() == 0) {
                addTotalBkey(eachResult);
                mergedResult.addAll(eachResult);
              }
 else {
                if (TRIMMED.equals(status.getMessage())) {
                }
                for (                SMGetElement<T> result : eachResult) {
                  boolean added=false;
                  for (int i=0; i < mergedResult.size(); i++) {
                    if (i > totalResultElementCount) {
                      added=true;
                      break;
                    }
                    if ((reverse) ? (0 > result.compareTo(mergedResult.get(i))) : 0 < result.compareTo(mergedResult.get(i))) {
                      if (!addTotalBkey(result.getBkeyByObject())) {
                        resultOperationStatus.add(new OperationStatus(true,"String_Node_Str"));
                      }
                      mergedResult.add(i,result);
                      added=true;
                      break;
                    }
                  }
                  if (!added) {
                    if (!addTotalBkey(result.getBkeyByObject())) {
                      resultOperationStatus.add(new OperationStatus(true,"String_Node_Str"));
                    }
                    mergedResult.add(result);
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          getLogger().warn("String_Node_Str",status);
        }
      }
      @Override public void complete(){
        blatch.countDown();
      }
      @Override public void gotData(      String key,      Object subkey,      int flags,      byte[] data){
        if (stopCollect.get())         return;
        if (subkey instanceof Long) {
          eachResult.add(new SMGetElement<T>(key,(Long)subkey,tc.decode(new CachedData(flags,data,tc.getMaxSize()))));
        }
 else         if (subkey instanceof byte[]) {
          eachResult.add(new SMGetElement<T>(key,(byte[])subkey,tc.decode(new CachedData(flags,data,tc.getMaxSize()))));
        }
      }
      @Override public void gotMissedKey(      byte[] data){
        missedKey.add(new String(data));
      }
    }
);
    ops.add(op);
    addOp(smGet.getRepresentKey(),op);
  }
  return new SMGetFuture<List<SMGetElement<T>>>(ops,operationTimeout){
    @Override public List<SMGetElement<T>> get(    long duration,    TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException {
      if (!blatch.await(duration,units)) {
        for (        Operation op : ops) {
          MemcachedConnection.opTimedOut(op);
        }
        throw new CheckedOperationTimeoutException("String_Node_Str",ops);
      }
 else {
        for (        Operation op : ops) {
          MemcachedConnection.opSucceeded(op);
        }
      }
      for (      Operation op : ops) {
        if (op != null && op.hasErrored()) {
          throw new ExecutionException(op.getException());
        }
      }
      if (isCancelled()) {
        throw new ExecutionException(new RuntimeException("String_Node_Str"));
      }
      if (smGetList.size() == 1)       return mergedResult;
      return getSubList(mergedResult,offset,count);
    }
    @Override public List<String> getMissedKeyList(){
      return missedKey;
    }
    @Override public CollectionOperationStatus getOperationStatus(){
      if (failedOperationStatus.size() > 0) {
        return new CollectionOperationStatus(failedOperationStatus.get(0));
      }
      OperationStatus end=null;
      OperationStatus duplicated=null;
      OperationStatus trimmed=null;
      OperationStatus duplicatedTrimmed=null;
      for (      OperationStatus status : resultOperationStatus) {
        if (END.equals(status.getMessage()))         end=status;
 else         if (DUPLICATED.equals(status.getMessage()))         duplicated=status;
 else         if (TRIMMED.equals(status.getMessage()))         trimmed=status;
 else         if (DUPLICATED_TRIMMED.equals(status.getMessage()))         duplicatedTrimmed=status;
      }
      if (end == null && duplicated == null && trimmed == null && duplicatedTrimmed == null) {
        getLogger().warn("String_Node_Str");
        return null;
      }
      if (duplicatedTrimmed != null || (duplicated != null && trimmed != null))       return new CollectionOperationStatus(duplicatedTrimmed);
 else       if (duplicated != null)       return new CollectionOperationStatus(duplicated);
 else       if (trimmed != null)       return new CollectionOperationStatus(trimmed);
 else       return new CollectionOperationStatus(end);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Generic smget operation for b+tree items. Public smget methods call this method.
 * @param smGetList  smget parameters (keys, eflags, and so on)
 * @param offset  start index of the elements
 * @param count  number of elements to fetch
 * @param reverse  forward or backward
 * @param tc  transcoder to serialize and unserialize element value
 * @return future holding the smget result (elements, return codes, and so on)
 */
private <T>SMGetFuture<List<SMGetElement<T>>> smget(final List<BTreeSMGet<T>> smGetList,final int offset,final int count,final boolean reverse,final Transcoder<T> tc){
  final String END="String_Node_Str";
  final String TRIMMED="String_Node_Str";
  final String DUPLICATED="String_Node_Str";
  final String DUPLICATED_TRIMMED="String_Node_Str";
  final CountDownLatch blatch=new CountDownLatch(smGetList.size());
  final ConcurrentLinkedQueue<Operation> ops=new ConcurrentLinkedQueue<Operation>();
  final List<String> missedKey=Collections.synchronizedList(new ArrayList<String>());
  final int totalResultElementCount=count + offset;
  final List<SMGetElement<T>> mergedResult=Collections.synchronizedList(new ArrayList<SMGetElement<T>>(totalResultElementCount));
  final ReentrantLock lock=new ReentrantLock();
  final List<OperationStatus> resultOperationStatus=Collections.synchronizedList(new ArrayList<OperationStatus>(1));
  final List<OperationStatus> failedOperationStatus=Collections.synchronizedList(new ArrayList<OperationStatus>(1));
  final Set<Object> totalBkey=new TreeSet<Object>();
  final AtomicBoolean stopCollect=new AtomicBoolean(false);
  for (  BTreeSMGet<T> smGet : smGetList) {
    Operation op=opFact.bopsmget(smGet,new BTreeSortMergeGetOperation.Callback(){
      final List<SMGetElement<T>> eachResult=new ArrayList<SMGetElement<T>>();
      private void addTotalBkey(      List<SMGetElement<T>> smgetresult){
        for (        SMGetElement<T> each : smgetresult) {
          if (each.getBkeyByObject() instanceof byte[]) {
            totalBkey.add(new ByteArrayBKey((byte[])each.getBkeyByObject()));
          }
 else {
            totalBkey.add(each.getBkeyByObject());
          }
        }
      }
      private boolean addTotalBkey(      Object bkey){
        if (bkey instanceof byte[]) {
          return totalBkey.add(new ByteArrayBKey((byte[])bkey));
        }
 else {
          return totalBkey.add(bkey);
        }
      }
      @Override public void receivedStatus(      OperationStatus status){
        if (status.isSuccess()) {
          resultOperationStatus.add(status);
        }
 else {
          stopCollect.set(true);
          mergedResult.clear();
          failedOperationStatus.add(status);
        }
        if (status.isSuccess()) {
          lock.lock();
          try {
            if (smGetList.size() == 1) {
              addTotalBkey(eachResult);
              mergedResult.addAll(eachResult);
            }
 else {
              if (mergedResult.size() == 0) {
                addTotalBkey(eachResult);
                mergedResult.addAll(eachResult);
              }
 else {
                if (TRIMMED.equals(status.getMessage())) {
                }
                for (                SMGetElement<T> result : eachResult) {
                  boolean added=false;
                  for (int i=0; i < mergedResult.size(); i++) {
                    if (i > totalResultElementCount) {
                      added=true;
                      break;
                    }
                    if ((reverse) ? (0 > result.compareTo(mergedResult.get(i))) : 0 < result.compareTo(mergedResult.get(i))) {
                      if (!addTotalBkey(result.getBkeyByObject())) {
                        resultOperationStatus.add(new OperationStatus(true,"String_Node_Str"));
                      }
                      mergedResult.add(i,result);
                      added=true;
                      break;
                    }
                  }
                  if (!added) {
                    if (!addTotalBkey(result.getBkeyByObject())) {
                      resultOperationStatus.add(new OperationStatus(true,"String_Node_Str"));
                    }
                    mergedResult.add(result);
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          getLogger().warn("String_Node_Str",status);
        }
      }
      @Override public void complete(){
        blatch.countDown();
      }
      @Override public void gotData(      String key,      Object subkey,      int flags,      byte[] data){
        if (stopCollect.get())         return;
        if (subkey instanceof Long) {
          eachResult.add(new SMGetElement<T>(key,(Long)subkey,tc.decode(new CachedData(flags,data,tc.getMaxSize()))));
        }
 else         if (subkey instanceof byte[]) {
          eachResult.add(new SMGetElement<T>(key,(byte[])subkey,tc.decode(new CachedData(flags,data,tc.getMaxSize()))));
        }
      }
      @Override public void gotMissedKey(      byte[] data){
        missedKey.add(new String(data));
      }
    }
);
    ops.add(op);
    addOp(smGet.getRepresentKey(),op);
  }
  return new SMGetFuture<List<SMGetElement<T>>>(ops,operationTimeout){
    @Override public List<SMGetElement<T>> get(    long duration,    TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException {
      if (!blatch.await(duration,units)) {
        for (        Operation op : ops) {
          MemcachedConnection.opTimedOut(op);
        }
        throw new CheckedOperationTimeoutException("String_Node_Str",ops);
      }
 else {
        for (        Operation op : ops) {
          MemcachedConnection.opSucceeded(op);
        }
      }
      for (      Operation op : ops) {
        if (op != null && op.hasErrored()) {
          throw new ExecutionException(op.getException());
        }
      }
      if (isCancelled()) {
        throw new ExecutionException(new RuntimeException("String_Node_Str"));
      }
      if (smGetList.size() == 1)       return mergedResult;
      return getSubList(mergedResult,offset,count);
    }
    @Override public List<String> getMissedKeyList(){
      return missedKey;
    }
    @Override public CollectionOperationStatus getOperationStatus(){
      if (failedOperationStatus.size() > 0) {
        return new CollectionOperationStatus(failedOperationStatus.get(0));
      }
      OperationStatus end=null;
      OperationStatus duplicated=null;
      OperationStatus trimmed=null;
      OperationStatus duplicatedTrimmed=null;
      for (      OperationStatus status : resultOperationStatus) {
        if (END.equals(status.getMessage()))         end=status;
 else         if (DUPLICATED.equals(status.getMessage()))         duplicated=status;
 else         if (TRIMMED.equals(status.getMessage()))         trimmed=status;
 else         if (DUPLICATED_TRIMMED.equals(status.getMessage()))         duplicatedTrimmed=status;
      }
      if (end == null && duplicated == null && trimmed == null && duplicatedTrimmed == null) {
        getLogger().warn("String_Node_Str");
        return null;
      }
      if (duplicatedTrimmed == null && duplicated != null && trimmed != null)       duplicatedTrimmed=new OperationStatus(true,"String_Node_Str");
      if (duplicatedTrimmed != null)       return new CollectionOperationStatus(duplicatedTrimmed);
 else       if (duplicated != null)       return new CollectionOperationStatus(duplicated);
 else       if (trimmed != null)       return new CollectionOperationStatus(trimmed);
 else       return new CollectionOperationStatus(end);
    }
  }
;
}