Program: 22722
Project: 22722
Buggy source:
/** 
 * <p>Builds the popup window's content and returns the height the popup should have. Returns -1 when the content already exists.</p>
 * @return the content's height or -1 if content already exists
 */
private int buildDropDown(){
  ViewGroup dropDownView;
  int otherHeights=0;
  final ListAdapter adapter=mAdapter;
  if (adapter != null) {
    InputMethodManager imm=InputMethodManager.peekInstance();
    if (imm != null) {
      final int count=Math.min(adapter.getCount(),20);
      CompletionInfo[] completions=new CompletionInfo[count];
      int realCount=0;
      for (int i=0; i < count; i++) {
        if (adapter.isEnabled(i)) {
          realCount++;
          Object item=adapter.getItem(i);
          long id=adapter.getItemId(i);
          completions[i]=new CompletionInfo(id,i,convertSelectionToString(item));
        }
      }
      if (realCount != count) {
        CompletionInfo[] tmp=new CompletionInfo[realCount];
        System.arraycopy(completions,0,tmp,0,realCount);
        completions=tmp;
      }
      imm.displayCompletions(this,completions);
    }
  }
  if (mDropDownList == null) {
    Context context=getContext();
    mHideSelector=new ListSelectorHider();
    mShowDropDownRunnable=new Runnable(){
      public void run(){
        View view=getDropDownAnchorView();
        if (view != null && view.getWindowToken() != null) {
          showDropDown();
        }
      }
    }
;
    mDropDownList=new DropDownListView(context);
    mDropDownList.setSelector(mDropDownListHighlight);
    mDropDownList.setAdapter(adapter);
    mDropDownList.setVerticalFadingEdgeEnabled(true);
    mDropDownList.setOnItemClickListener(mDropDownItemClickListener);
    mDropDownList.setFocusable(true);
    mDropDownList.setFocusableInTouchMode(true);
    mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
      public void onItemSelected(      AdapterView<?> parent,      View view,      int position,      long id){
        if (position != -1) {
          DropDownListView dropDownList=mDropDownList;
          if (dropDownList != null) {
            dropDownList.mListSelectionHidden=false;
          }
        }
      }
      public void onNothingSelected(      AdapterView<?> parent){
      }
    }
);
    if (mItemSelectedListener != null) {
      mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
    }
    dropDownView=mDropDownList;
    View hintView=getHintView(context);
    if (hintView != null) {
      LinearLayout hintContainer=new LinearLayout(context);
      hintContainer.setOrientation(LinearLayout.VERTICAL);
      LinearLayout.LayoutParams hintParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1.0f);
      hintContainer.addView(dropDownView,hintParams);
      hintContainer.addView(hintView);
      int widthSpec=MeasureSpec.makeMeasureSpec(getWidth(),MeasureSpec.AT_MOST);
      int heightSpec=MeasureSpec.UNSPECIFIED;
      hintView.measure(widthSpec,heightSpec);
      hintParams=(LinearLayout.LayoutParams)hintView.getLayoutParams();
      otherHeights=hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
      dropDownView=hintContainer;
    }
    mPopup.setContentView(dropDownView);
  }
 else {
    dropDownView=(ViewGroup)mPopup.getContentView();
    final View view=dropDownView.findViewById(HINT_VIEW_ID);
    if (view != null) {
      LinearLayout.LayoutParams hintParams=(LinearLayout.LayoutParams)view.getLayoutParams();
      otherHeights=view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
    }
  }
  boolean ignoreBottomDecorations=mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
  final int maxHeight=mPopup.getMaxAvailableHeight(getDropDownAnchorView(),mDropDownVerticalOffset,ignoreBottomDecorations);
  int padding=0;
  Drawable background=mPopup.getBackground();
  if (background != null) {
    background.getPadding(mTempRect);
    padding=mTempRect.top + mTempRect.bottom;
  }
  if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
    return maxHeight + padding;
  }
  final int listContent=mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,0,ListView.NO_POSITION,maxHeight - otherHeights,2);
  if (listContent > 0)   otherHeights+=padding;
  return listContent + otherHeights;
}

Fixed version (ground truth):
/** 
 * <p>Builds the popup window's content and returns the height the popup should have. Returns -1 when the content already exists.</p>
 * @return the content's height or -1 if content already exists
 */
private int buildDropDown(){
  ViewGroup dropDownView;
  int otherHeights=0;
  final ListAdapter adapter=mAdapter;
  if (adapter != null) {
    InputMethodManager imm=InputMethodManager.peekInstance();
    if (imm != null) {
      final int count=Math.min(adapter.getCount(),20);
      CompletionInfo[] completions=new CompletionInfo[count];
      int realCount=0;
      for (int i=0; i < count; i++) {
        if (adapter.isEnabled(i)) {
          realCount++;
          Object item=adapter.getItem(i);
          long id=adapter.getItemId(i);
          completions[i]=new CompletionInfo(id,i,convertSelectionToString(item));
        }
      }
      if (realCount != count) {
        CompletionInfo[] tmp=new CompletionInfo[realCount];
        System.arraycopy(completions,0,tmp,0,realCount);
        completions=tmp;
      }
      imm.displayCompletions(this,completions);
    }
  }
  if (mDropDownList == null) {
    Context context=getContext();
    mHideSelector=new ListSelectorHider();
    mShowDropDownRunnable=new Runnable(){
      public void run(){
        View view=getDropDownAnchorView();
        if (view != null && view.getWindowToken() != null) {
          showDropDown();
        }
      }
    }
;
    mDropDownList=new DropDownListView(context);
    mDropDownList.setSelector(mDropDownListHighlight);
    mDropDownList.setAdapter(adapter);
    mDropDownList.setVerticalFadingEdgeEnabled(true);
    mDropDownList.setOnItemClickListener(mDropDownItemClickListener);
    mDropDownList.setFocusable(true);
    mDropDownList.setFocusableInTouchMode(true);
    mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
      public void onItemSelected(      AdapterView<?> parent,      View view,      int position,      long id){
        if (position != -1) {
          DropDownListView dropDownList=mDropDownList;
          if (dropDownList != null) {
            dropDownList.mListSelectionHidden=false;
          }
        }
      }
      public void onNothingSelected(      AdapterView<?> parent){
      }
    }
);
    mDropDownList.setOnScrollListener(new PopupScrollListener());
    if (mItemSelectedListener != null) {
      mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
    }
    dropDownView=mDropDownList;
    View hintView=getHintView(context);
    if (hintView != null) {
      LinearLayout hintContainer=new LinearLayout(context);
      hintContainer.setOrientation(LinearLayout.VERTICAL);
      LinearLayout.LayoutParams hintParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1.0f);
      hintContainer.addView(dropDownView,hintParams);
      hintContainer.addView(hintView);
      int widthSpec=MeasureSpec.makeMeasureSpec(getWidth(),MeasureSpec.AT_MOST);
      int heightSpec=MeasureSpec.UNSPECIFIED;
      hintView.measure(widthSpec,heightSpec);
      hintParams=(LinearLayout.LayoutParams)hintView.getLayoutParams();
      otherHeights=hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
      dropDownView=hintContainer;
    }
    mPopup.setContentView(dropDownView);
  }
 else {
    dropDownView=(ViewGroup)mPopup.getContentView();
    final View view=dropDownView.findViewById(HINT_VIEW_ID);
    if (view != null) {
      LinearLayout.LayoutParams hintParams=(LinearLayout.LayoutParams)view.getLayoutParams();
      otherHeights=view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
    }
  }
  boolean ignoreBottomDecorations=mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
  final int maxHeight=mPopup.getMaxAvailableHeight(getDropDownAnchorView(),mDropDownVerticalOffset,ignoreBottomDecorations);
  int padding=0;
  Drawable background=mPopup.getBackground();
  if (background != null) {
    background.getPadding(mTempRect);
    padding=mTempRect.top + mTempRect.bottom;
  }
  if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
    return maxHeight + padding;
  }
  final int listContent=mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,0,ListView.NO_POSITION,maxHeight - otherHeights,2);
  if (listContent > 0)   otherHeights+=padding;
  return listContent + otherHeights;
}