Program: 171970
Project: 171970
Buggy source:
/** 
 * 若发现有足够的连续消息，则直接返回。否则去服务器查询消息，同时消除断点。
 */
private void processStorageQueryResult(List<AVIMMessage> cachedMessages,List<Boolean> breakpoints,String originMsgId,long originMsgTS,int limit,final AVIMMessagesQueryCallback callback){
  final List<AVIMMessage> continuousMessages=new ArrayList<AVIMMessage>();
  int firstBreakPointIndex=-1;
  for (int index=0; index < cachedMessages.size(); index++) {
    if (breakpoints.get(index)) {
      firstBreakPointIndex=index;
      break;
    }
 else {
      continuousMessages.add(cachedMessages.get(index));
    }
  }
  final boolean connected=AVUtils.isConnected(AVOSCloud.applicationContext);
  if (!connected || continuousMessages.size() >= limit - 1) {
    Collections.sort(cachedMessages,messageComparator);
    callback.internalDone(cachedMessages,null);
  }
 else {
    final int restCount;
    final AVIMMessage startMessage;
    if (firstBreakPointIndex > 0 && firstBreakPointIndex < cachedMessages.size()) {
      restCount=limit - continuousMessages.size() + 1;
      startMessage=cachedMessages.get(firstBreakPointIndex - 1);
      continuousMessages.add(startMessage);
    }
 else     if (!continuousMessages.isEmpty()) {
      restCount=limit - continuousMessages.size();
      startMessage=continuousMessages.get(continuousMessages.size() - 1);
    }
 else {
      startMessage=null;
      restCount=limit;
    }
    queryMessagesFromServer(startMessage == null ? originMsgId : startMessage.messageId,startMessage == null ? originMsgTS : startMessage.timestamp,restCount,null,0,new AVIMMessagesQueryCallback(){
      @Override public void done(      List<AVIMMessage> serverMessages,      AVIMException e){
        if (e != null) {
          callback.internalDone(e);
        }
 else {
          if (serverMessages == null) {
            serverMessages=new ArrayList<AVIMMessage>();
          }
          continuousMessages.addAll(serverMessages);
          processContinuousMessages(continuousMessages);
          callback.internalDone(continuousMessages,null);
        }
      }
    }
);
  }
}

Fixed version (ground truth):
/** 
 * 若发现有足够的连续消息，则直接返回。否则去服务器查询消息，同时消除断点。
 */
private void processStorageQueryResult(List<AVIMMessage> cachedMessages,List<Boolean> breakpoints,String originMsgId,long originMsgTS,int limit,final AVIMMessagesQueryCallback callback){
  final List<AVIMMessage> continuousMessages=new ArrayList<AVIMMessage>();
  int firstBreakPointIndex=-1;
  for (int index=0; index < cachedMessages.size(); index++) {
    if (breakpoints.get(index)) {
      firstBreakPointIndex=index;
      break;
    }
 else {
      continuousMessages.add(cachedMessages.get(index));
    }
  }
  final boolean connected=AVUtils.isConnected(AVOSCloud.applicationContext);
  if (!connected || continuousMessages.size() >= limit) {
    Collections.sort(continuousMessages,messageComparator);
    callback.internalDone(continuousMessages,null);
  }
 else {
    final int restCount;
    final AVIMMessage startMessage;
    if (!continuousMessages.isEmpty()) {
      restCount=limit - continuousMessages.size();
      startMessage=continuousMessages.get(continuousMessages.size() - 1);
    }
 else {
      startMessage=null;
      restCount=limit;
    }
    queryMessagesFromServer(startMessage == null ? originMsgId : startMessage.messageId,startMessage == null ? originMsgTS : startMessage.timestamp,restCount,null,0,new AVIMMessagesQueryCallback(){
      @Override public void done(      List<AVIMMessage> serverMessages,      AVIMException e){
        if (e != null) {
          if (continuousMessages.size() > 0) {
            callback.internalDone(continuousMessages,null);
          }
 else {
            callback.internalDone(e);
          }
        }
 else {
          if (serverMessages == null) {
            serverMessages=new ArrayList<AVIMMessage>();
          }
          continuousMessages.addAll(serverMessages);
          processContinuousMessages(continuousMessages);
          callback.internalDone(continuousMessages,null);
        }
      }
    }
);
  }
}