Program: 86273
Project: 86273
Buggy source:
protected void buildSearchForm(){
  if (app.getLibrary().getReplacedBy() != null && sp.getInt("String_Node_Str",0) < 5) {
    view.findViewById(R.id.rlReplaced).setVisibility(View.VISIBLE);
    view.findViewById(R.id.ivReplacedStore).setOnClickListener(new OnClickListener(){
      @Override public void onClick(      View v){
        try {
          Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("String_Node_Str" + app.getLibrary().getReplacedBy()));
          startActivity(i);
        }
 catch (        ActivityNotFoundException e) {
          Log.i("String_Node_Str","String_Node_Str");
        }
      }
    }
);
    sp.edit().putInt("String_Node_Str",sp.getInt("String_Node_Str",0) + 1).commit();
  }
 else {
    view.findViewById(R.id.rlReplaced).setVisibility(View.GONE);
  }
  LinearLayout llFormFields=(LinearLayout)view.findViewById(R.id.llFormFields);
  llFormFields.removeAllViews();
  LinearLayout llAdvancedFields=(LinearLayout)view.findViewById(R.id.llAdvancedFields);
  llAdvancedFields.removeAllViews();
  LinearLayout llExpand=(LinearLayout)view.findViewById(R.id.llExpand);
  llExpand.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      setAdvanced(!advanced);
    }
  }
);
  RelativeLayout rlSimpleSearch=(RelativeLayout)view.findViewById(R.id.rlSimpleSearch);
  TextView tvSearchAdvHeader=(TextView)view.findViewById(R.id.tvSearchAdvHeader);
  EditText etSimpleSearch=(EditText)view.findViewById(R.id.etSimpleSearch);
  rlSimpleSearch.setVisibility(View.GONE);
  tvSearchAdvHeader.setVisibility(View.GONE);
  int i=0;
  if (fields == null)   return;
  for (  final SearchField field : fields) {
    ViewGroup v=null;
    if (field instanceof TextSearchField) {
      TextSearchField textSearchField=(TextSearchField)field;
      if (textSearchField.isFreeSearch()) {
        rlSimpleSearch.setVisibility(View.VISIBLE);
        tvSearchAdvHeader.setVisibility(View.VISIBLE);
        etSimpleSearch.setHint(textSearchField.getHint());
      }
 else {
        v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_text,llFormFields,false);
        TextView title=(TextView)v.findViewById(R.id.title);
        title.setText(textSearchField.getDisplayName());
        EditText edittext=(EditText)v.findViewById(R.id.edittext);
        edittext.setHint(textSearchField.getHint());
        if (((TextSearchField)field).isNumber()) {
          edittext.setInputType(InputType.TYPE_CLASS_NUMBER);
        }
        if (((TextSearchField)field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField)fields.get(i - 1)).isFreeSearch())) {
          ViewGroup before=(ViewGroup)view.findViewWithTag(fields.get(i - 1).getId());
          llFormFields.removeView(before);
          llAdvancedFields.removeView(before);
          v=makeHalfWidth(before,v);
        }
      }
    }
 else     if (field instanceof BarcodeSearchField) {
      BarcodeSearchField bcSearchField=(BarcodeSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_barcode,llFormFields,false);
      TextView title=(TextView)v.findViewById(R.id.title);
      title.setText(bcSearchField.getDisplayName());
      EditText edittext=(EditText)v.findViewById(R.id.edittext);
      edittext.setHint(bcSearchField.getHint());
      ImageView ivBarcode=(ImageView)v.findViewById(R.id.ivBarcode);
      ivBarcode.setOnClickListener(new OnClickListener(){
        @Override public void onClick(        View arg0){
          barcodeScanningField=field.getId();
          mCallback.scanBarcode();
        }
      }
);
      if (((BarcodeSearchField)field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField)fields.get(i - 1)).isFreeSearch())) {
        ViewGroup before=(ViewGroup)view.findViewWithTag(fields.get(i - 1).getId());
        llFormFields.removeView(before);
        llAdvancedFields.removeView(before);
        v=makeHalfWidth(before,v);
      }
    }
 else     if (field instanceof DropdownSearchField) {
      DropdownSearchField ddSearchField=(DropdownSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_dropdown,llFormFields,false);
      TextView title=(TextView)v.findViewById(R.id.title);
      title.setText(ddSearchField.getDisplayName());
      Spinner spinner=(Spinner)v.findViewById(R.id.spinner);
      spinner.setAdapter(((OpacActivity)getActivity()).new MetaAdapter(getActivity(),ddSearchField.getDropdownValues(),R.layout.simple_spinner_item));
    }
 else     if (field instanceof CheckboxSearchField) {
      CheckboxSearchField cbSearchField=(CheckboxSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_checkbox,llFormFields,false);
      CheckBox checkbox=(CheckBox)v.findViewById(R.id.checkbox);
      checkbox.setText(cbSearchField.getDisplayName());
    }
    if (v != null) {
      v.setTag(field.getId());
      if (field.isAdvanced())       llAdvancedFields.addView(v);
 else       llFormFields.addView(v);
    }
    i++;
  }
}

Fixed version (ground truth):
protected void buildSearchForm(){
  if (app.getLibrary().getReplacedBy() != null && sp.getInt("String_Node_Str",0) < 5) {
    view.findViewById(R.id.rlReplaced).setVisibility(View.VISIBLE);
    view.findViewById(R.id.ivReplacedStore).setOnClickListener(new OnClickListener(){
      @Override public void onClick(      View v){
        try {
          Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("String_Node_Str" + app.getLibrary().getReplacedBy()));
          startActivity(i);
        }
 catch (        ActivityNotFoundException e) {
          Log.i("String_Node_Str","String_Node_Str");
        }
      }
    }
);
    sp.edit().putInt("String_Node_Str",sp.getInt("String_Node_Str",0) + 1).commit();
  }
 else {
    view.findViewById(R.id.rlReplaced).setVisibility(View.GONE);
  }
  LinearLayout llFormFields=(LinearLayout)view.findViewById(R.id.llFormFields);
  llFormFields.removeAllViews();
  LinearLayout llAdvancedFields=(LinearLayout)view.findViewById(R.id.llAdvancedFields);
  llAdvancedFields.removeAllViews();
  LinearLayout llExpand=(LinearLayout)view.findViewById(R.id.llExpand);
  llExpand.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      setAdvanced(!advanced);
    }
  }
);
  RelativeLayout rlSimpleSearch=(RelativeLayout)view.findViewById(R.id.rlSimpleSearch);
  TextView tvSearchAdvHeader=(TextView)view.findViewById(R.id.tvSearchAdvHeader);
  EditText etSimpleSearch=(EditText)view.findViewById(R.id.etSimpleSearch);
  rlSimpleSearch.setVisibility(View.GONE);
  tvSearchAdvHeader.setVisibility(View.GONE);
  int i=0;
  if (fields == null)   return;
  for (  final SearchField field : fields) {
    ViewGroup v=null;
    if (field instanceof TextSearchField) {
      TextSearchField textSearchField=(TextSearchField)field;
      if (textSearchField.isFreeSearch()) {
        rlSimpleSearch.setVisibility(View.VISIBLE);
        tvSearchAdvHeader.setVisibility(View.VISIBLE);
        etSimpleSearch.setHint(textSearchField.getHint());
      }
 else {
        v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_text,llFormFields,false);
        TextView title=(TextView)v.findViewById(R.id.title);
        title.setText(textSearchField.getDisplayName());
        EditText edittext=(EditText)v.findViewById(R.id.edittext);
        edittext.setHint(textSearchField.getHint());
        if (((TextSearchField)field).isNumber()) {
          edittext.setInputType(InputType.TYPE_CLASS_NUMBER);
        }
        if (((TextSearchField)field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField)fields.get(i - 1)).isFreeSearch())) {
          ViewGroup before=(ViewGroup)view.findViewWithTag(fields.get(i - 1).getId());
          llFormFields.removeView(before);
          llAdvancedFields.removeView(before);
          v.setTag(field.getId());
          View together=makeHalfWidth(before,v);
          v=null;
          if (field.isAdvanced())           llAdvancedFields.addView(together);
 else           llFormFields.addView(together);
        }
      }
    }
 else     if (field instanceof BarcodeSearchField) {
      BarcodeSearchField bcSearchField=(BarcodeSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_barcode,llFormFields,false);
      TextView title=(TextView)v.findViewById(R.id.title);
      title.setText(bcSearchField.getDisplayName());
      EditText edittext=(EditText)v.findViewById(R.id.edittext);
      edittext.setHint(bcSearchField.getHint());
      ImageView ivBarcode=(ImageView)v.findViewById(R.id.ivBarcode);
      ivBarcode.setOnClickListener(new OnClickListener(){
        @Override public void onClick(        View arg0){
          barcodeScanningField=field.getId();
          mCallback.scanBarcode();
        }
      }
);
      if (((BarcodeSearchField)field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField)fields.get(i - 1)).isFreeSearch())) {
        ViewGroup before=(ViewGroup)view.findViewWithTag(fields.get(i - 1).getId());
        llFormFields.removeView(before);
        llAdvancedFields.removeView(before);
        v=makeHalfWidth(before,v);
      }
    }
 else     if (field instanceof DropdownSearchField) {
      DropdownSearchField ddSearchField=(DropdownSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_dropdown,llFormFields,false);
      TextView title=(TextView)v.findViewById(R.id.title);
      title.setText(ddSearchField.getDisplayName());
      Spinner spinner=(Spinner)v.findViewById(R.id.spinner);
      spinner.setAdapter(((OpacActivity)getActivity()).new MetaAdapter(getActivity(),ddSearchField.getDropdownValues(),R.layout.simple_spinner_item));
    }
 else     if (field instanceof CheckboxSearchField) {
      CheckboxSearchField cbSearchField=(CheckboxSearchField)field;
      v=(ViewGroup)getLayoutInflater().inflate(R.layout.searchfield_checkbox,llFormFields,false);
      CheckBox checkbox=(CheckBox)v.findViewById(R.id.checkbox);
      checkbox.setText(cbSearchField.getDisplayName());
    }
    if (v != null) {
      v.setTag(field.getId());
      if (field.isAdvanced())       llAdvancedFields.addView(v);
 else       llFormFields.addView(v);
    }
    i++;
  }
}