Program: 32064
Project: 32064
Buggy source:
/** 
 * Recursive method to search a media by its name. It does not seem to have a msgtype filter in the current Server APi. So, the reponses are merged until to find at least 10 medias or there is no more message
 * @param response      the recursive response.
 * @param name          the file name to search
 * @param rooms         the rooms list to search in
 * @param messageTypes  the supported media types.
 * @param beforeLimit   the number of events to get before the matching results.
 * @param afterLimit    the number of events to get after the matching results.
 * @param nextBatch     the token to pass for doing pagination from a previous response.
 * @param callback      the request callback
 */
private void mediaSearch(final SearchResponse response,final String name,final List<String> rooms,final List<String> messageTypes,final int beforeLimit,final int afterLimit,final String nextBatch,final ApiCallback<SearchResponse> callback){
  SearchParams searchParams=new SearchParams();
  SearchRoomEventCategoryParams searchEventParams=new SearchRoomEventCategoryParams();
  searchEventParams.search_term=name;
  searchEventParams.order_by="String_Node_Str";
  searchEventParams.event_context=new HashMap<>();
  searchEventParams.event_context.put("String_Node_Str",beforeLimit);
  searchEventParams.event_context.put("String_Node_Str",afterLimit);
  searchEventParams.event_context.put("String_Node_Str",true);
  searchEventParams.filter=new HashMap<>();
  if (null != rooms) {
    searchEventParams.filter.put("String_Node_Str",rooms);
  }
  ArrayList<String> types=new ArrayList<>();
  types.add("String_Node_Str");
  searchEventParams.filter.put("String_Node_Str",rooms);
  searchParams.search_categories=new HashMap<>();
  searchParams.search_categories.put("String_Node_Str",searchEventParams);
  mSearchMediaName=name;
  final String description="String_Node_Str";
  mApi.search(searchParams,nextBatch,new RestAdapterCallback<SearchResponse>(description,null,new ApiCallback<SearchResponse>(){
    @Override public void onSuccess(    SearchResponse newSearchResponse){
      if (TextUtils.equals(mSearchMediaName,name)) {
        if ((null == newSearchResponse.searchCategories.roomEvents.results) || (0 == newSearchResponse.searchCategories.roomEvents.results.size())) {
          callback.onSuccess(response);
          mSearchMediaName=null;
        }
 else {
          SearchResponse mergedResponse=mergeAndFilterResponse(response,newSearchResponse,messageTypes);
          if (mergedResponse.searchCategories.roomEvents.results.size() >= 10) {
            callback.onSuccess(mergedResponse);
            mSearchMediaName=null;
          }
 else {
            mediaSearch(mergedResponse,name,rooms,messageTypes,beforeLimit,afterLimit,mergedResponse.searchCategories.roomEvents.nextBatch,callback);
          }
        }
      }
    }
    @Override public void onNetworkError(    Exception e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onNetworkError(e);
        mSearchMediaName=null;
      }
    }
    @Override public void onMatrixError(    MatrixError e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onMatrixError(e);
        mSearchMediaName=null;
      }
    }
    @Override public void onUnexpectedError(    Exception e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onUnexpectedError(e);
        mSearchMediaName=null;
      }
    }
  }
,new RestAdapterCallback.RequestRetryCallBack(){
    @Override public void onRetry(){
      mediaSearch(response,name,rooms,messageTypes,beforeLimit,afterLimit,nextBatch,callback);
    }
  }
));
}

Fixed version (ground truth):
/** 
 * Recursive method to search a media by its name. It does not seem to have a msgtype filter in the current Server APi. So, the reponses are merged until to find at least 10 medias or there is no more message
 * @param response      the recursive response.
 * @param name          the file name to search
 * @param rooms         the rooms list to search in
 * @param messageTypes  the supported media types.
 * @param beforeLimit   the number of events to get before the matching results.
 * @param afterLimit    the number of events to get after the matching results.
 * @param nextBatch     the token to pass for doing pagination from a previous response.
 * @param callback      the request callback
 */
private void mediaSearch(final SearchResponse response,final String name,final List<String> rooms,final List<String> messageTypes,final int beforeLimit,final int afterLimit,final String nextBatch,final ApiCallback<SearchResponse> callback){
  SearchParams searchParams=new SearchParams();
  SearchRoomEventCategoryParams searchEventParams=new SearchRoomEventCategoryParams();
  searchEventParams.search_term=name;
  searchEventParams.order_by="String_Node_Str";
  searchEventParams.event_context=new HashMap<>();
  searchEventParams.event_context.put("String_Node_Str",beforeLimit);
  searchEventParams.event_context.put("String_Node_Str",afterLimit);
  searchEventParams.event_context.put("String_Node_Str",true);
  searchEventParams.filter=new HashMap<>();
  if (null != rooms) {
    searchEventParams.filter.put("String_Node_Str",rooms);
  }
  ArrayList<String> types=new ArrayList<>();
  types.add(Event.EVENT_TYPE_MESSAGE);
  searchEventParams.filter.put("String_Node_Str",types);
  searchParams.search_categories=new HashMap<>();
  searchParams.search_categories.put("String_Node_Str",searchEventParams);
  mSearchMediaName=name;
  final String description="String_Node_Str";
  mApi.search(searchParams,nextBatch,new RestAdapterCallback<SearchResponse>(description,null,new ApiCallback<SearchResponse>(){
    @Override public void onSuccess(    SearchResponse newSearchResponse){
      if (TextUtils.equals(mSearchMediaName,name)) {
        if ((null == newSearchResponse.searchCategories.roomEvents.results) || (0 == newSearchResponse.searchCategories.roomEvents.results.size())) {
          callback.onSuccess(response);
          mSearchMediaName=null;
        }
 else {
          SearchResponse mergedResponse=mergeAndFilterResponse(response,newSearchResponse,messageTypes);
          if (mergedResponse.searchCategories.roomEvents.results.size() >= 10) {
            callback.onSuccess(mergedResponse);
            mSearchMediaName=null;
          }
 else {
            mediaSearch(mergedResponse,name,rooms,messageTypes,beforeLimit,afterLimit,mergedResponse.searchCategories.roomEvents.nextBatch,callback);
          }
        }
      }
    }
    @Override public void onNetworkError(    Exception e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onNetworkError(e);
        mSearchMediaName=null;
      }
    }
    @Override public void onMatrixError(    MatrixError e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onMatrixError(e);
        mSearchMediaName=null;
      }
    }
    @Override public void onUnexpectedError(    Exception e){
      if (TextUtils.equals(mSearchMediaName,name)) {
        callback.onUnexpectedError(e);
        mSearchMediaName=null;
      }
    }
  }
,new RestAdapterCallback.RequestRetryCallBack(){
    @Override public void onRetry(){
      mediaSearch(response,name,rooms,messageTypes,beforeLimit,afterLimit,nextBatch,callback);
    }
  }
));
}