Program: 146271
Project: 146271
Buggy source:
@Override protected void beforeSetUpCommoditySearch(){
  Intent intent=getIntent();
  String allocationId=intent.getStringExtra(ALLOCATION_ID);
  if (StringUtils.isNotBlank(allocationId)) {
    Allocation allocationWithId=allocationService.getAllocationByLmisId(allocationId);
    if (allocationWithId != null && !allocationWithId.isReceived()) {
      presetAllocationId=allocationId;
    }
  }
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),R.layout.spinner_item_black,getReceiveSources());
  spinnerSource.setAdapter(adapter);
  spinnerSource.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> adapterView,    View view,    int position,    long l){
      String selected=getReceiveSources().get(position);
      if (selected.contains(getString(R.string.lga))) {
        setAllocation(textViewAllocationId.getText().toString());
        textViewAllocationId.setEnabled(true);
        textViewAllocationId.setVisibility(View.VISIBLE);
        textViewAllocationLabel.setVisibility(View.VISIBLE);
      }
 else {
        allocation=null;
        textViewAllocationId.setError(null);
        textViewAllocationId.setVisibility(View.INVISIBLE);
        textViewAllocationLabel.setVisibility(View.INVISIBLE);
        textViewAllocationId.setEnabled(false);
      }
      List<CommodityToggledEvent> events=new ArrayList<CommodityToggledEvent>();
      if (selected.contains(getString(R.string.zonal_store))) {
        for (        BaseCommodityViewModel model : selectedCommodities) {
          if (!model.getCommodity().isNonLGA()) {
            events.add(new CommodityToggledEvent(model));
          }
        }
      }
 else {
        for (        BaseCommodityViewModel model : selectedCommodities) {
          if (model.getCommodity().isNonLGA()) {
            events.add(new CommodityToggledEvent(model));
          }
        }
      }
      for (      CommodityToggledEvent event : events) {
        onEvent(event);
      }
      ((ReceiveCommoditiesAdapter)arrayAdapter).setQuantityAllocatedDisplay(!selected.contains(getString(R.string.others)) && !selected.contains(getString(R.string.zonal_store)));
      arrayAdapter.notifyDataSetChanged();
    }
    @Override public void onNothingSelected(    AdapterView<?> adapterView){
    }
  }
);
}

Fixed version (ground truth):
@Override protected void beforeSetUpCommoditySearch(){
  Intent intent=getIntent();
  String allocationId=intent.getStringExtra(ALLOCATION_ID);
  if (StringUtils.isNotBlank(allocationId)) {
    Allocation allocationWithId=allocationService.getAllocationByLmisId(allocationId);
    if (allocationWithId != null && !allocationWithId.isReceived()) {
      presetAllocationId=allocationId;
    }
  }
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),R.layout.spinner_item_black,getReceiveSources());
  spinnerSource.setAdapter(adapter);
  spinnerSource.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> adapterView,    View view,    int position,    long l){
      String selected=getReceiveSources().get(position);
      if (selected.contains(getString(R.string.lga_for_receive))) {
        setAllocation(textViewAllocationId.getText().toString());
        textViewAllocationId.setEnabled(true);
        textViewAllocationId.setVisibility(View.VISIBLE);
        textViewAllocationLabel.setVisibility(View.VISIBLE);
      }
 else {
        allocation=null;
        textViewAllocationId.setError(null);
        textViewAllocationId.setVisibility(View.INVISIBLE);
        textViewAllocationLabel.setVisibility(View.INVISIBLE);
        textViewAllocationId.setEnabled(false);
      }
      List<CommodityToggledEvent> events=new ArrayList<CommodityToggledEvent>();
      if (selected.contains(getString(R.string.zonal_store_for_receive))) {
        for (        BaseCommodityViewModel model : selectedCommodities) {
          if (!model.getCommodity().isNonLGA()) {
            events.add(new CommodityToggledEvent(model));
          }
        }
      }
 else {
        for (        BaseCommodityViewModel model : selectedCommodities) {
          if (model.getCommodity().isNonLGA()) {
            events.add(new CommodityToggledEvent(model));
          }
        }
      }
      for (      CommodityToggledEvent event : events) {
        onEvent(event);
      }
      ((ReceiveCommoditiesAdapter)arrayAdapter).setQuantityAllocatedDisplay(!selected.contains(getString(R.string.others_for_receive)) && !selected.contains(getString(R.string.zonal_store_for_receive)));
      arrayAdapter.notifyDataSetChanged();
    }
    @Override public void onNothingSelected(    AdapterView<?> adapterView){
    }
  }
);
}