Program: 52627
Project: 52627
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mTwoPane=getResources().getBoolean(R.bool.has_two_panes);
  resolveIntentAction(getIntent());
  if (mSelectedTaskUri != null) {
    if (mShouldShowDetails && mShouldSwitchToDetail) {
      Intent viewTaskIntent=new Intent(Intent.ACTION_VIEW);
      viewTaskIntent.setData(mSelectedTaskUri);
      startActivity(viewTaskIntent);
      mShouldSwitchToDetail=false;
      mTransientState=true;
    }
  }
 else {
    mShouldShowDetails=false;
  }
  setContentView(R.layout.activity_task_list);
  mAppBarLayout=(AppBarLayout)findViewById(R.id.appbar);
  Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  mAuthority=AuthorityUtil.taskAuthority(this);
  mSearchHistoryHelper=new SearchHistoryHelper(this);
  if (findViewById(R.id.task_detail_container) != null) {
    loadTaskDetailFragment(mSelectedTaskUri);
  }
 else {
    FragmentManager fragmentManager=getSupportFragmentManager();
    Fragment detailFragment=fragmentManager.findFragmentByTag(DETAIL_FRAGMENT_TAG);
    if (detailFragment != null) {
      fragmentManager.beginTransaction().remove(detailFragment).commit();
    }
  }
  mGroupingFactories=new AbstractGroupingFactory[]{new ByList(mAuthority,this),new ByDueDate(mAuthority),new ByStartDate(mAuthority),new ByPriority(mAuthority,this),new ByProgress(mAuthority),new BySearch(mAuthority,mSearchHistoryHelper)};
  mPagerAdapter=new Unchecked<>(() -> new TaskGroupPagerAdapter(getSupportFragmentManager(),mGroupingFactories,this,R.xml.listview_tabs)).value();
  mPagerAdapter.setTwoPaneLayout(mTwoPane);
  mViewPager=(ViewPager)findViewById(R.id.pager);
  mViewPager.setAdapter(mPagerAdapter);
  int currentPageIndex=mPagerAdapter.getPagePosition(mCurrentPageId);
  if (currentPageIndex >= 0) {
    mCurrentPagePosition=currentPageIndex;
    mViewPager.setCurrentItem(currentPageIndex);
    if (mCurrentPageId == R.id.task_group_search) {
      if (mSearchItem != null) {
        MenuItemCompat.expandActionView(mSearchItem);
      }
 else {
        mAutoExpandSearchView=true;
      }
    }
  }
  updateTitle(currentPageIndex);
  mTabs=(TabLayout)findViewById(R.id.tabs);
  mTabs.setupWithViewPager(mViewPager);
  for (int i=0, count=mPagerAdapter.getCount(); i < count; ++i) {
    mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
  }
  mViewPager.addOnPageChangeListener(new OnPageChangeListener(){
    @Override public void onPageSelected(    int position){
      mSelectedTaskUri=null;
      mCurrentPagePosition=position;
      int newPageId=mPagerAdapter.getPageId(mCurrentPagePosition);
      if (newPageId == R.id.task_group_search) {
        int oldPageId=mCurrentPageId;
        mCurrentPageId=newPageId;
        mPreviousPagePosition=mPagerAdapter.getPagePosition(oldPageId);
      }
 else       if (mCurrentPageId == R.id.task_group_search) {
        mSearchHistoryHelper.commitSearch();
        mHandler.post(mSearchUpdater);
        mCurrentPageId=newPageId;
        hideSearchActionView();
      }
      mCurrentPageId=newPageId;
      updateTitle(mCurrentPageId);
    }
    @Override public void onPageScrolled(    int position,    float positionOffset,    int positionOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
      if (state == ViewPager.SCROLL_STATE_IDLE && mCurrentPageId == R.id.task_group_search) {
        mHandler.postDelayed(new Runnable(){
          @Override public void run(){
            MenuItemCompat.expandActionView(mSearchItem);
          }
        }
,50);
      }
    }
  }
);
  mFloatingActionButton=(FloatingActionButton)findViewById(R.id.floating_action_button);
  if (mFloatingActionButton != null) {
    mFloatingActionButton.setOnClickListener(new OnClickListener(){
      @Override public void onClick(      View v){
        onAddNewTask();
      }
    }
);
  }
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mTwoPane=getResources().getBoolean(R.bool.has_two_panes);
  resolveIntentAction(getIntent());
  if (mSelectedTaskUri != null) {
    if (mShouldShowDetails && mShouldSwitchToDetail) {
      Intent viewTaskIntent=new Intent(Intent.ACTION_VIEW);
      viewTaskIntent.setData(mSelectedTaskUri);
      startActivity(viewTaskIntent);
      mShouldSwitchToDetail=false;
      mTransientState=true;
    }
  }
 else {
    mShouldShowDetails=false;
  }
  setContentView(R.layout.activity_task_list);
  mAppBarLayout=(AppBarLayout)findViewById(R.id.appbar);
  Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  mAuthority=AuthorityUtil.taskAuthority(this);
  mSearchHistoryHelper=new SearchHistoryHelper(this);
  if (findViewById(R.id.task_detail_container) != null) {
    loadTaskDetailFragment(mSelectedTaskUri);
  }
 else {
    FragmentManager fragmentManager=getSupportFragmentManager();
    Fragment detailFragment=fragmentManager.findFragmentByTag(DETAIL_FRAGMENT_TAG);
    if (detailFragment != null) {
      fragmentManager.beginTransaction().remove(detailFragment).commit();
    }
  }
  mGroupingFactories=new AbstractGroupingFactory[]{new ByList(mAuthority,this),new ByDueDate(mAuthority),new ByStartDate(mAuthority),new ByPriority(mAuthority,this),new ByProgress(mAuthority),new BySearch(mAuthority,mSearchHistoryHelper)};
  mPagerAdapter=new Unchecked<>(() -> new TaskGroupPagerAdapter(getSupportFragmentManager(),mGroupingFactories,this,R.xml.listview_tabs)).value();
  mPagerAdapter.setTwoPaneLayout(mTwoPane);
  mViewPager=(ViewPager)findViewById(R.id.pager);
  mViewPager.setAdapter(mPagerAdapter);
  int currentPageIndex=mPagerAdapter.getPagePosition(mCurrentPageId);
  if (currentPageIndex >= 0) {
    mCurrentPagePosition=currentPageIndex;
    mViewPager.setCurrentItem(currentPageIndex);
    if (mCurrentPageId == R.id.task_group_search) {
      if (mSearchItem != null) {
        MenuItemCompat.expandActionView(mSearchItem);
      }
 else {
        mAutoExpandSearchView=true;
      }
    }
  }
  updateTitle(currentPageIndex);
  mTabs=(TabLayout)findViewById(R.id.tabs);
  mTabs.setupWithViewPager(mViewPager);
  setupTabIcons();
  mViewPager.addOnPageChangeListener(new OnPageChangeListener(){
    @Override public void onPageSelected(    int position){
      mSelectedTaskUri=null;
      mCurrentPagePosition=position;
      int newPageId=mPagerAdapter.getPageId(mCurrentPagePosition);
      if (newPageId == R.id.task_group_search) {
        int oldPageId=mCurrentPageId;
        mCurrentPageId=newPageId;
        mPreviousPagePosition=mPagerAdapter.getPagePosition(oldPageId);
      }
 else       if (mCurrentPageId == R.id.task_group_search) {
        mSearchHistoryHelper.commitSearch();
        mHandler.post(mSearchUpdater);
        mCurrentPageId=newPageId;
        hideSearchActionView();
      }
      mCurrentPageId=newPageId;
      updateTitle(mCurrentPageId);
    }
    @Override public void onPageScrolled(    int position,    float positionOffset,    int positionOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
      if (state == ViewPager.SCROLL_STATE_IDLE && mCurrentPageId == R.id.task_group_search) {
        mHandler.postDelayed(new Runnable(){
          @Override public void run(){
            MenuItemCompat.expandActionView(mSearchItem);
          }
        }
,50);
      }
    }
  }
);
  mFloatingActionButton=(FloatingActionButton)findViewById(R.id.floating_action_button);
  if (mFloatingActionButton != null) {
    mFloatingActionButton.setOnClickListener(new OnClickListener(){
      @Override public void onClick(      View v){
        onAddNewTask();
      }
    }
);
  }
}