Program: 14936
Project: 14936
Buggy source:
public void refreshMediaFromServer(int offset){
  if (offset == 0 || !mIsRefreshing) {
    if (offset == mOldMediaSyncOffset) {
      offset=0;
    }
    mOldMediaSyncOffset=offset;
    mIsRefreshing=true;
    mGridAdapter.setRefreshing(true);
    List<Object> apiArgs=new ArrayList<Object>();
    apiArgs.add(WordPress.getCurrentBlog());
    ApiHelper.SyncMediaLibraryTask.Callback callback=new ApiHelper.SyncMediaLibraryTask.Callback(){
      @Override public void onSuccess(      int count){
        MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
        mHasRetrievedAllMedia=(count == 0);
        adapter.setHasRetrieviedAll(mHasRetrievedAllMedia);
        String blogId=String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId());
        if (WordPress.wpDB.getMediaCountAll(blogId) == 0 && count == 0) {
          noMediaFinish();
        }
        mIsRefreshing=false;
        if (!isFinishing()) {
          runOnUiThread(new Runnable(){
            @Override public void run(){
              mGridAdapter.setRefreshing(false);
              String blogId=String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId());
              Cursor cursor=WordPress.wpDB.getMediaImagesForBlog(blogId,mFilteredItems);
              mGridAdapter.swapCursor(cursor);
            }
          }
);
        }
      }
      @Override public void onFailure(      ApiHelper.ErrorType errorType,      String errorMessage,      Throwable throwable){
        if (errorType == ApiHelper.ErrorType.NO_ERROR) {
          String message=errorType == ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP ? getString(R.string.media_error_no_permission) : getString(R.string.error_refresh_media);
          Toast.makeText(MediaGalleryPickerActivity.this,message,Toast.LENGTH_SHORT).show();
          MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
          mHasRetrievedAllMedia=true;
          adapter.setHasRetrieviedAll(mHasRetrievedAllMedia);
        }
        if (!isFinishing()) {
          runOnUiThread(new Runnable(){
            @Override public void run(){
              mIsRefreshing=false;
              mGridAdapter.setRefreshing(false);
            }
          }
);
        }
      }
    }
;
    ApiHelper.SyncMediaLibraryTask getMediaTask=new ApiHelper.SyncMediaLibraryTask(offset,MediaGridFragment.Filter.ALL,callback);
    getMediaTask.execute(apiArgs);
  }
}

Fixed version (ground truth):
public void refreshMediaFromServer(int offset){
  if (offset == 0 || !mIsRefreshing) {
    if (offset == mOldMediaSyncOffset) {
      offset=0;
    }
    mOldMediaSyncOffset=offset;
    mIsRefreshing=true;
    mGridAdapter.setRefreshing(true);
    List<Object> apiArgs=new ArrayList<Object>();
    apiArgs.add(WordPress.getCurrentBlog());
    ApiHelper.SyncMediaLibraryTask.Callback callback=new ApiHelper.SyncMediaLibraryTask.Callback(){
      @Override public void onSuccess(      int count){
        MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
        mHasRetrievedAllMedia=(count == 0);
        adapter.setHasRetrieviedAll(mHasRetrievedAllMedia);
        String blogId=String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId());
        if (WordPress.wpDB.getMediaCountAll(blogId) == 0 && count == 0) {
          noMediaFinish();
        }
        mIsRefreshing=false;
        if (!isFinishing()) {
          runOnUiThread(new Runnable(){
            @Override public void run(){
              mGridAdapter.setRefreshing(false);
              String blogId=String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId());
              Cursor cursor=WordPress.wpDB.getMediaImagesForBlog(blogId,mFilteredItems);
              mGridAdapter.swapCursor(cursor);
            }
          }
);
        }
      }
      @Override public void onFailure(      ApiHelper.ErrorType errorType,      String errorMessage,      Throwable throwable){
        if (errorType != ApiHelper.ErrorType.NO_ERROR) {
          String message=errorType == ApiHelper.ErrorType.NO_UPLOAD_FILES_CAP ? getString(R.string.media_error_no_permission) : getString(R.string.error_refresh_media);
          Toast.makeText(MediaGalleryPickerActivity.this,message,Toast.LENGTH_SHORT).show();
          MediaGridAdapter adapter=(MediaGridAdapter)mGridView.getAdapter();
          mHasRetrievedAllMedia=true;
          adapter.setHasRetrieviedAll(mHasRetrievedAllMedia);
        }
        if (!isFinishing()) {
          runOnUiThread(new Runnable(){
            @Override public void run(){
              mIsRefreshing=false;
              mGridAdapter.setRefreshing(false);
            }
          }
);
        }
      }
    }
;
    ApiHelper.SyncMediaLibraryTask getMediaTask=new ApiHelper.SyncMediaLibraryTask(offset,MediaGridFragment.Filter.ALL,callback);
    getMediaTask.execute(apiArgs);
  }
}