Program: 171967
Project: 171967
Buggy source:
/** 
 * 查询消息记录，上拉时使用。
 * @param msgId 消息id，从消息id开始向前查询
 * @param timestamp 查询起始的时间戳，返回小于这个时间的记录。客户端时间不可靠，请用 0 代替 System.currentTimeMillis()
 * @param limit 返回条数限制
 * @param callback
 */
public void queryMessages(final String msgId,final long timestamp,final int limit,final AVIMMessagesQueryCallback callback){
  if (AVUtils.isBlankString(msgId) && timestamp == 0) {
    this.queryMessages(limit,callback);
    return;
  }
  if (!AVIMClient.messageQueryCacheEnabled) {
    queryMessagesFromServer(msgId,timestamp,limit,null,0,new AVIMMessagesQueryCallback(){
      @Override public void done(      List<AVIMMessage> messages,      AVIMException e){
        if (callback != null) {
          if (e != null) {
            callback.internalDone(e);
          }
 else {
            callback.internalDone(messages,null);
          }
        }
      }
    }
);
    return;
  }
  storage.getMessage(msgId,timestamp,conversationId,new AVIMMessageStorage.StorageMessageCallback(){
    @Override public void done(    final AVIMMessage indicatorMessage,    final boolean isIndicateMessageBreakPoint){
      if (indicatorMessage == null || isIndicateMessageBreakPoint) {
        String startMsgId=msgId;
        long startTS=timestamp;
        int requestLimit=limit;
        if (indicatorMessage != null && isIndicateMessageBreakPoint) {
          AVIMMessage nextMessage=storage.getNextMessage(indicatorMessage);
          if (nextMessage != null) {
            startMsgId=nextMessage.getMessageId();
            startTS=nextMessage.getTimestamp();
            requestLimit=limit + 1;
          }
        }
        queryMessagesFromServer(startMsgId,startTS,requestLimit,null,0,new AVIMMessagesQueryCallback(){
          @Override public void done(          List<AVIMMessage> messages,          AVIMException e){
            if (e != null) {
              callback.internalDone(e);
            }
 else {
              if (messages == null) {
                messages=new LinkedList<AVIMMessage>();
              }
              processContinuousMessages(messages);
              queryMessagesFromCache(msgId,timestamp,limit,callback);
            }
          }
        }
);
      }
 else {
        storage.getMessages(msgId,timestamp,limit,conversationId,new AVIMMessageStorage.StorageQueryCallback(){
          @Override public void done(          List<AVIMMessage> messages,          List<Boolean> breakpoints){
            processStorageQueryResult(messages,breakpoints,msgId,timestamp,limit,callback);
          }
        }
);
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * 查询消息记录，上拉时使用。
 * @param msgId 消息id，从消息id开始向前查询
 * @param timestamp 查询起始的时间戳，返回小于这个时间的记录。客户端时间不可靠，请用 0 代替 System.currentTimeMillis()
 * @param limit 返回条数限制
 * @param callback
 */
public void queryMessages(final String msgId,final long timestamp,final int limit,final AVIMMessagesQueryCallback callback){
  if (AVUtils.isBlankString(msgId) && timestamp == 0) {
    this.queryMessages(limit,callback);
    return;
  }
  if (!AVIMClient.messageQueryCacheEnabled) {
    queryMessagesFromServer(msgId,timestamp,limit,null,0,new AVIMMessagesQueryCallback(){
      @Override public void done(      List<AVIMMessage> messages,      AVIMException e){
        if (callback != null) {
          if (e != null) {
            callback.internalDone(e);
          }
 else {
            callback.internalDone(messages,null);
          }
        }
      }
    }
);
    return;
  }
  storage.getMessage(msgId,timestamp,conversationId,new AVIMMessageStorage.StorageMessageCallback(){
    @Override public void done(    final AVIMMessage indicatorMessage,    final boolean isIndicateMessageBreakPoint){
      if (indicatorMessage == null || isIndicateMessageBreakPoint) {
        String startMsgId=msgId;
        long startTS=timestamp;
        int requestLimit=limit;
        queryMessagesFromServer(startMsgId,startTS,requestLimit,null,0,new AVIMMessagesQueryCallback(){
          @Override public void done(          List<AVIMMessage> messages,          AVIMException e){
            if (e != null) {
              callback.internalDone(e);
            }
 else {
              List<AVIMMessage> cachedMsgs=new LinkedList<AVIMMessage>();
              if (indicatorMessage != null) {
                cachedMsgs.add(indicatorMessage);
              }
              if (messages != null) {
                cachedMsgs.addAll(messages);
              }
              processContinuousMessages(cachedMsgs);
              queryMessagesFromCache(msgId,timestamp,limit,callback);
            }
          }
        }
);
      }
 else {
        storage.getMessages(msgId,timestamp,limit,conversationId,new AVIMMessageStorage.StorageQueryCallback(){
          @Override public void done(          List<AVIMMessage> messages,          List<Boolean> breakpoints){
            processStorageQueryResult(messages,breakpoints,msgId,timestamp,limit,callback);
          }
        }
);
      }
    }
  }
);
}