Program: 14421
Project: 14421
Buggy source:
public void refreshMediaFromServer(int offset,final boolean auto){
  if (WordPress.getCurrentBlog() == null || mFilter == Filter.CUSTOM_DATE) {
    setRefreshing(false);
    return;
  }
  if (mSearchTerm != null && mSearchTerm.length() > 0) {
    setRefreshing(false);
    return;
  }
  if (offset == 0 || !mIsRefreshing) {
    if (offset == mOldMediaSyncOffset) {
      offset=0;
    }
    mOldMediaSyncOffset=offset;
    mIsRefreshing=true;
    updateEmptyView(MessageType.LOADING);
    mListener.onMediaItemListDownloadStart();
    mGridAdapter.setRefreshing(true);
    List<Object> apiArgs=new ArrayList<Object>();
    apiArgs.add(WordPress.getCurrentBlog());
    Callback callback=new Callback(){
      @Override public void onSuccess(      int count){
        MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
        mHasRetrievedAllMedia=(count == 0);
        adapter.setHasRetrievedAll(mHasRetrievedAllMedia);
        mIsRefreshing=false;
        if (getActivity() != null && MediaGridFragment.this.isVisible()) {
          getActivity().runOnUiThread(new Runnable(){
            @Override public void run(){
              refreshSpinnerAdapter();
              updateEmptyView(MessageType.NO_CONTENT);
              if (!auto) {
                mGridView.setSelection(0);
              }
              mListener.onMediaItemListDownloaded();
              mGridAdapter.setRefreshing(false);
              mSwipeToRefreshHelper.setRefreshing(false);
            }
          }
);
        }
      }
      @Override public void onFailure(      final ApiHelper.ErrorType errorType,      String errorMessage,      Throwable throwable){
        if (errorType != ApiHelper.ErrorType.NO_ERROR) {
          if (getActivity() != null) {
            if (errorType != ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP) {
              ToastUtils.showToast(getActivity(),getString(R.string.error_refresh_media),Duration.LONG);
            }
 else {
              if (mEmptyView == null || mEmptyView.getVisibility() != View.VISIBLE) {
                ToastUtils.showToast(getActivity(),getString(R.string.media_error_no_permission));
              }
            }
          }
          MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
          mHasRetrievedAllMedia=true;
          adapter.setHasRetrievedAll(mHasRetrievedAllMedia);
        }
        if (getActivity() != null && MediaGridFragment.this.isVisible()) {
          getActivity().runOnUiThread(new Runnable(){
            @Override public void run(){
              mIsRefreshing=false;
              mListener.onMediaItemListDownloaded();
              mGridAdapter.setRefreshing(false);
              mSwipeToRefreshHelper.setRefreshing(false);
              if (errorType == ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP) {
                updateEmptyView(MessageType.PERMISSION_ERROR);
              }
 else {
                updateEmptyView(MessageType.GENERIC_ERROR);
              }
            }
          }
);
        }
      }
    }
;
    ApiHelper.SyncMediaLibraryTask getMediaTask=new ApiHelper.SyncMediaLibraryTask(offset,mFilter,callback);
    getMediaTask.execute(apiArgs);
  }
}

Fixed version (ground truth):
public void refreshMediaFromServer(int offset,final boolean auto){
  if (!NetworkUtils.isNetworkAvailable(getActivity())) {
    updateEmptyView(MessageType.NETWORK_ERROR);
    setRefreshing(false);
    return;
  }
  if (WordPress.getCurrentBlog() == null || mFilter == Filter.CUSTOM_DATE) {
    setRefreshing(false);
    return;
  }
  if (mSearchTerm != null && mSearchTerm.length() > 0) {
    setRefreshing(false);
    return;
  }
  if (offset == 0 || !mIsRefreshing) {
    if (offset == mOldMediaSyncOffset) {
      offset=0;
    }
    mOldMediaSyncOffset=offset;
    mIsRefreshing=true;
    updateEmptyView(MessageType.LOADING);
    mListener.onMediaItemListDownloadStart();
    mGridAdapter.setRefreshing(true);
    List<Object> apiArgs=new ArrayList<Object>();
    apiArgs.add(WordPress.getCurrentBlog());
    Callback callback=new Callback(){
      @Override public void onSuccess(      int count){
        MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
        mHasRetrievedAllMedia=(count == 0);
        adapter.setHasRetrievedAll(mHasRetrievedAllMedia);
        mIsRefreshing=false;
        if (getActivity() != null && MediaGridFragment.this.isVisible()) {
          getActivity().runOnUiThread(new Runnable(){
            @Override public void run(){
              refreshSpinnerAdapter();
              updateEmptyView(MessageType.NO_CONTENT);
              if (!auto) {
                mGridView.setSelection(0);
              }
              mListener.onMediaItemListDownloaded();
              mGridAdapter.setRefreshing(false);
              mSwipeToRefreshHelper.setRefreshing(false);
            }
          }
);
        }
      }
      @Override public void onFailure(      final ApiHelper.ErrorType errorType,      String errorMessage,      Throwable throwable){
        if (errorType != ApiHelper.ErrorType.NO_ERROR) {
          if (getActivity() != null) {
            if (errorType != ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP) {
              ToastUtils.showToast(getActivity(),getString(R.string.error_refresh_media),Duration.LONG);
            }
 else {
              if (mEmptyView == null || mEmptyView.getVisibility() != View.VISIBLE) {
                ToastUtils.showToast(getActivity(),getString(R.string.media_error_no_permission));
              }
            }
          }
          MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
          mHasRetrievedAllMedia=true;
          adapter.setHasRetrievedAll(mHasRetrievedAllMedia);
        }
        if (getActivity() != null && MediaGridFragment.this.isVisible()) {
          getActivity().runOnUiThread(new Runnable(){
            @Override public void run(){
              mIsRefreshing=false;
              mListener.onMediaItemListDownloaded();
              mGridAdapter.setRefreshing(false);
              mSwipeToRefreshHelper.setRefreshing(false);
              if (errorType == ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP) {
                updateEmptyView(MessageType.PERMISSION_ERROR);
              }
 else {
                updateEmptyView(MessageType.GENERIC_ERROR);
              }
            }
          }
);
        }
      }
    }
;
    ApiHelper.SyncMediaLibraryTask getMediaTask=new ApiHelper.SyncMediaLibraryTask(offset,mFilter,callback);
    getMediaTask.execute(apiArgs);
  }
}