Program: 13547
Project: 13547
Buggy source:
private void setupTabs(){
  if (shouldShowTabs()) {
    int normalColor=ContextCompat.getColor(this,R.color.blue_light);
    int selectedColor=ContextCompat.getColor(this,R.color.white);
    mTabLayout.setTabTextColors(normalColor,selectedColor);
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_all));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_images));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_documents));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_videos));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_audio));
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
      @Override public void onTabSelected(      TabLayout.Tab tab){
        setFilter(getFilterForPosition(tab.getPosition()));
      }
      @Override public void onTabUnselected(      TabLayout.Tab tab){
      }
      @Override public void onTabReselected(      TabLayout.Tab tab){
        setFilter(getFilterForPosition(tab.getPosition()));
      }
    }
);
    mTabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
      @Override public void onGlobalLayout(){
        mTabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        if (mTabLayout.getChildCount() > 0) {
          int tabLayoutWidth=0;
          LinearLayout tabFirstChild=(LinearLayout)mTabLayout.getChildAt(0);
          for (int i=0; i < mTabLayout.getTabCount(); i++) {
            LinearLayout tabView=(LinearLayout)(tabFirstChild.getChildAt(i));
            tabLayoutWidth+=(tabView.getMeasuredWidth() + tabView.getPaddingLeft() + tabView.getPaddingRight());
          }
          int displayWidth=DisplayUtils.getDisplayPixelWidth(MediaBrowserActivity.this);
          if (tabLayoutWidth < displayWidth) {
            mTabLayout.setTabMode(TabLayout.MODE_FIXED);
            mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
          }
        }
      }
    }
);
  }
 else {
    mTabLayout.setVisibility(View.GONE);
  }
}

Fixed version (ground truth):
private void setupTabs(){
  if (shouldShowTabs()) {
    int normalColor=ContextCompat.getColor(this,R.color.blue_light);
    int selectedColor=ContextCompat.getColor(this,R.color.white);
    mTabLayout.setTabTextColors(normalColor,selectedColor);
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_all));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_images));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_documents));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_videos));
    mTabLayout.addTab(mTabLayout.newTab().setText(R.string.media_audio));
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
      @Override public void onTabSelected(      TabLayout.Tab tab){
        setFilter(getFilterForPosition(tab.getPosition()));
      }
      @Override public void onTabUnselected(      TabLayout.Tab tab){
      }
      @Override public void onTabReselected(      TabLayout.Tab tab){
        setFilter(getFilterForPosition(tab.getPosition()));
      }
    }
);
    mTabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
      @Override public void onGlobalLayout(){
        mTabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        if (mTabLayout.getChildCount() > 0) {
          int tabLayoutWidth=0;
          LinearLayout tabFirstChild=(LinearLayout)mTabLayout.getChildAt(0);
          for (int i=0; i < mTabLayout.getTabCount(); i++) {
            LinearLayout tabView=(LinearLayout)(tabFirstChild.getChildAt(i));
            tabLayoutWidth+=(tabView.getMeasuredWidth() + ViewCompat.getPaddingStart(tabView) + ViewCompat.getPaddingEnd(tabView));
          }
          int displayWidth=DisplayUtils.getDisplayPixelWidth(MediaBrowserActivity.this);
          if (tabLayoutWidth < displayWidth) {
            mTabLayout.setTabMode(TabLayout.MODE_FIXED);
            mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
          }
        }
      }
    }
);
  }
 else {
    mTabLayout.setVisibility(View.GONE);
  }
}