Program: 86166
Project: 86166
Buggy source:
protected void buildSearchForm(Map<String,String> restoreQuery){
  if (app.getLibrary().getReplacedBy() != null && sp.getInt("String_Node_Str",0) < 5) {
    rlReplaced.setVisibility(View.VISIBLE);
    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 {
    rlReplaced.setVisibility(View.GONE);
  }
  llFormFields.removeAllViews();
  llAdvancedFields.removeAllViews();
  llExpand.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      setAdvanced(!advanced);
    }
  }
);
  rlSimpleSearch.setVisibility(View.GONE);
  tvSearchAdvHeader.setVisibility(View.GONE);
  int i=0;
  if (fields == null) {
    return;
  }
  for (  final SearchField field : fields) {
    if (!field.isVisible()) {
      continue;
    }
    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(null).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(null).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();
          callback.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;
      if (ddSearchField.getDropdownValues() == null) {
        continue;
      }
      v=(ViewGroup)getLayoutInflater(null).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<DropdownSearchField.Option>(getActivity(),ddSearchField.getDropdownValues(),R.layout.simple_spinner_item));
      if (field.getMeaning() == Meaning.HOME_BRANCH) {
        String selection;
        if (sp.contains(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId())) {
          selection=sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(),"String_Node_Str");
        }
 else {
          try {
            selection=app.getLibrary().getData().getString("String_Node_Str");
          }
 catch (          JSONException e) {
            selection="String_Node_Str";
          }
        }
        if (!selection.equals("String_Node_Str")) {
          int j=0;
          for (          DropdownSearchField.Option row : ddSearchField.getDropdownValues()) {
            if (row.getKey().equals(selection)) {
              spinner.setSelection(j);
            }
            j++;
          }
        }
      }
    }
 else     if (field instanceof CheckboxSearchField) {
      CheckboxSearchField cbSearchField=(CheckboxSearchField)field;
      v=(ViewGroup)getLayoutInflater(null).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++;
  }
  llExpand.setVisibility(llAdvancedFields.getChildCount() == 0 ? View.GONE : View.VISIBLE);
  if (restoreQuery != null) {
    loadQuery(restoreQuery);
  }
}

Fixed version (ground truth):
protected void buildSearchForm(Map<String,String> restoreQuery){
  if (app.getLibrary().getReplacedBy() != null && sp.getInt("String_Node_Str",0) < 5) {
    rlReplaced.setVisibility(View.VISIBLE);
    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 {
    rlReplaced.setVisibility(View.GONE);
  }
  llFormFields.removeAllViews();
  llAdvancedFields.removeAllViews();
  llExpand.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      setAdvanced(!advanced);
    }
  }
);
  rlSimpleSearch.setVisibility(View.GONE);
  tvSearchAdvHeader.setVisibility(View.GONE);
  int i=0;
  if (fields == null) {
    return;
  }
  for (  final SearchField field : fields) {
    if (!field.isVisible()) {
      continue;
    }
    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)getActivity().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)getActivity().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();
          callback.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;
      if (ddSearchField.getDropdownValues() == null) {
        continue;
      }
      v=(ViewGroup)getActivity().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<DropdownSearchField.Option>(getActivity(),ddSearchField.getDropdownValues(),R.layout.simple_spinner_item));
      if (field.getMeaning() == Meaning.HOME_BRANCH) {
        String selection;
        if (sp.contains(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId())) {
          selection=sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(),"String_Node_Str");
        }
 else {
          try {
            selection=app.getLibrary().getData().getString("String_Node_Str");
          }
 catch (          JSONException e) {
            selection="String_Node_Str";
          }
        }
        if (!selection.equals("String_Node_Str")) {
          int j=0;
          for (          DropdownSearchField.Option row : ddSearchField.getDropdownValues()) {
            if (row.getKey().equals(selection)) {
              spinner.setSelection(j);
            }
            j++;
          }
        }
      }
    }
 else     if (field instanceof CheckboxSearchField) {
      CheckboxSearchField cbSearchField=(CheckboxSearchField)field;
      v=(ViewGroup)getActivity().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++;
  }
  llExpand.setVisibility(llAdvancedFields.getChildCount() == 0 ? View.GONE : View.VISIBLE);
  if (restoreQuery != null) {
    loadQuery(restoreQuery);
  }
}