Program: 194874
Project: 194874
Buggy source:
/** 
 * Fits as many menu items in the main panel and returns a list of the menu items that were not fit in.
 * @return The menu items that are not included in this main panel.
 */
public List<MenuItem> layoutMenuItems(List<MenuItem> menuItems,int suggestedWidth){
  Preconditions.checkNotNull(menuItems);
  final int toolbarWidth=getAdjustedToolbarWidth(mContext,suggestedWidth) - getEstimatedOpenOverflowButtonWidth(mContext);
  int availableWidth=toolbarWidth;
  final LinkedList<MenuItem> remainingMenuItems=new LinkedList<MenuItem>(menuItems);
  mContentView.removeAllViews();
  boolean isFirstItem=true;
  while (!remainingMenuItems.isEmpty()) {
    final MenuItem menuItem=remainingMenuItems.peek();
    View menuItemButton=createMenuItemButton(mContext,menuItem);
    if (isFirstItem) {
      menuItemButton.setPaddingRelative((int)(1.5 * menuItemButton.getPaddingStart()),menuItemButton.getPaddingTop(),menuItemButton.getPaddingEnd(),menuItemButton.getPaddingBottom());
      isFirstItem=false;
    }
    if (remainingMenuItems.size() == 1) {
      menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(),menuItemButton.getPaddingTop(),(int)(1.5 * menuItemButton.getPaddingEnd()),menuItemButton.getPaddingBottom());
    }
    menuItemButton.measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED);
    int menuItemButtonWidth=Math.min(menuItemButton.getMeasuredWidth(),toolbarWidth);
    if (menuItemButtonWidth <= availableWidth) {
      setButtonTagAndClickListener(menuItemButton,menuItem);
      mContentView.addView(menuItemButton);
      ViewGroup.LayoutParams params=menuItemButton.getLayoutParams();
      params.width=menuItemButtonWidth;
      menuItemButton.setLayoutParams(params);
      availableWidth-=menuItemButtonWidth;
      remainingMenuItems.pop();
    }
 else {
      if (mOpenOverflowButton == null) {
        mOpenOverflowButton=LayoutInflater.from(mContext).inflate(R.layout.floating_popup_open_overflow_button,null);
        mOpenOverflowButton.setOnClickListener(new View.OnClickListener(){
          @Override public void onClick(          View v){
            if (mOpenOverflowButton != null) {
              mOpenOverflow.run();
            }
          }
        }
);
      }
      mContentView.addView(mOpenOverflowButton);
      break;
    }
  }
  return remainingMenuItems;
}

Fixed version (ground truth):
/** 
 * Fits as many menu items in the main panel and returns a list of the menu items that were not fit in.
 * @return The menu items that are not included in this main panel.
 */
public List<MenuItem> layoutMenuItems(List<MenuItem> menuItems,int width){
  Preconditions.checkNotNull(menuItems);
  final int toolbarWidth=width - getEstimatedOpenOverflowButtonWidth(mContext);
  int availableWidth=toolbarWidth;
  final LinkedList<MenuItem> remainingMenuItems=new LinkedList<MenuItem>(menuItems);
  mContentView.removeAllViews();
  boolean isFirstItem=true;
  while (!remainingMenuItems.isEmpty()) {
    final MenuItem menuItem=remainingMenuItems.peek();
    View menuItemButton=createMenuItemButton(mContext,menuItem);
    if (isFirstItem) {
      menuItemButton.setPaddingRelative((int)(1.5 * menuItemButton.getPaddingStart()),menuItemButton.getPaddingTop(),menuItemButton.getPaddingEnd(),menuItemButton.getPaddingBottom());
      isFirstItem=false;
    }
    if (remainingMenuItems.size() == 1) {
      menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(),menuItemButton.getPaddingTop(),(int)(1.5 * menuItemButton.getPaddingEnd()),menuItemButton.getPaddingBottom());
    }
    menuItemButton.measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED);
    int menuItemButtonWidth=Math.min(menuItemButton.getMeasuredWidth(),toolbarWidth);
    if (menuItemButtonWidth <= availableWidth) {
      setButtonTagAndClickListener(menuItemButton,menuItem);
      mContentView.addView(menuItemButton);
      ViewGroup.LayoutParams params=menuItemButton.getLayoutParams();
      params.width=menuItemButtonWidth;
      menuItemButton.setLayoutParams(params);
      availableWidth-=menuItemButtonWidth;
      remainingMenuItems.pop();
    }
 else {
      if (mOpenOverflowButton == null) {
        mOpenOverflowButton=LayoutInflater.from(mContext).inflate(R.layout.floating_popup_open_overflow_button,null);
        mOpenOverflowButton.setOnClickListener(new View.OnClickListener(){
          @Override public void onClick(          View v){
            if (mOpenOverflowButton != null) {
              mOpenOverflow.run();
            }
          }
        }
);
      }
      mContentView.addView(mOpenOverflowButton);
      break;
    }
  }
  return remainingMenuItems;
}