Program: 142297
Project: 142297
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  try {
    platform=CommCareApplication._().getCommCarePlatform();
    setContentView(R.layout.entity_select_layout);
    findViewById(R.id.entity_select_loading).setVisibility(View.GONE);
    searchbox=(EditText)findViewById(R.id.searchbox);
    header=(LinearLayout)findViewById(R.id.entity_select_header);
    barcodeButton=(ImageButton)findViewById(R.id.barcodeButton);
    filterSelect=(Spinner)findViewById(R.id.entity_select_filter_dropdown);
    listView=(ListView)findViewById(R.id.screen_entity_select_list);
    listView.setOnItemClickListener(this);
    header.setVisibility(View.GONE);
    barcodeButton.setVisibility(View.GONE);
    TextView searchLabel=(TextView)findViewById(R.id.screen_entity_select_search_label);
    searchLabel.setText(Localization.get("String_Node_Str"));
    searchbox.addTextChangedListener(this);
    FormRecordLoaderTask task=new FormRecordLoaderTask(this,CommCareApplication._().getUserStorage(SessionStateDescriptor.class),platform);
    task.setListener(this);
    adapter=new IncompleteFormListAdapter(this,platform,task);
    FormRecordFilter filter=null;
    initialSelection=this.getIntent().getIntExtra(KEY_INITIAL_RECORD_ID,-1);
    if (this.getIntent().hasExtra(FormRecord.META_STATUS)) {
      String incomingFilter=this.getIntent().getStringExtra(FormRecord.META_STATUS);
      if (incomingFilter.equals(FormRecord.STATUS_INCOMPLETE)) {
        filter=FormRecordFilter.Incomplete;
      }
    }
 else {
      filter=FormRecordFilter.SubmittedAndPending;
      FormRecordFilter[] filters=FormRecordFilter.values();
      String[] names=new String[filters.length];
      for (int i=0; i < filters.length; ++i) {
        names[i]=Localization.get(filters[i].getMessage());
      }
      ArrayAdapter<String> spinneritems=new ArrayAdapter<String>(this,R.layout.form_filter_display,names);
      filterSelect.setAdapter(spinneritems);
      spinneritems.setDropDownViewResource(R.layout.form_filter_item);
      filterSelect.setOnItemSelectedListener(new OnItemSelectedListener(){
        @Override public void onItemSelected(        AdapterView<?> arg0,        View arg1,        int index,        long id){
          adapter.setFormFilter(FormRecordFilter.values()[index]);
          adapter.resetRecords();
          adapter.notifyDataSetChanged();
          invalidateOptionsMenu();
        }
        @Override public void onNothingSelected(        AdapterView<?> arg0){
        }
      }
);
      filterSelect.setVisibility(View.VISIBLE);
    }
    if (filter != null) {
      adapter.setFormFilter(filter);
    }
    this.registerForContextMenu(listView);
    refreshView();
  }
 catch (  SessionUnavailableException sue) {
  }
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  try {
    platform=CommCareApplication._().getCommCarePlatform();
    setContentView(R.layout.entity_select_layout);
    findViewById(R.id.entity_select_loading).setVisibility(View.GONE);
    searchbox=(EditText)findViewById(R.id.searchbox);
    header=(LinearLayout)findViewById(R.id.entity_select_header);
    barcodeButton=(ImageButton)findViewById(R.id.barcodeButton);
    filterSelect=(Spinner)findViewById(R.id.entity_select_filter_dropdown);
    listView=(ListView)findViewById(R.id.screen_entity_select_list);
    listView.setOnItemClickListener(this);
    header.setVisibility(View.GONE);
    barcodeButton.setVisibility(View.GONE);
    TextView searchLabel=(TextView)findViewById(R.id.screen_entity_select_search_label);
    searchLabel.setText(Localization.get("String_Node_Str"));
    searchbox.addTextChangedListener(this);
    FormRecordLoaderTask task=new FormRecordLoaderTask(this,CommCareApplication._().getUserStorage(SessionStateDescriptor.class),platform);
    task.setListener(this);
    adapter=new IncompleteFormListAdapter(this,platform,task);
    FormRecordFilter filter=null;
    initialSelection=this.getIntent().getIntExtra(KEY_INITIAL_RECORD_ID,-1);
    if (this.getIntent().hasExtra(FormRecord.META_STATUS)) {
      String incomingFilter=this.getIntent().getStringExtra(FormRecord.META_STATUS);
      if (incomingFilter.equals(FormRecord.STATUS_INCOMPLETE)) {
        filter=FormRecordFilter.Incomplete;
      }
    }
 else {
      filter=FormRecordFilter.SubmittedAndPending;
      FormRecordFilter[] filters=FormRecordFilter.values();
      String[] names=new String[filters.length];
      for (int i=0; i < filters.length; ++i) {
        names[i]=Localization.get(filters[i].getMessage());
      }
      ArrayAdapter<String> spinneritems=new ArrayAdapter<String>(this,R.layout.form_filter_display,names);
      filterSelect.setAdapter(spinneritems);
      spinneritems.setDropDownViewResource(R.layout.form_filter_item);
      filterSelect.setOnItemSelectedListener(new OnItemSelectedListener(){
        @Override public void onItemSelected(        AdapterView<?> arg0,        View arg1,        int index,        long id){
          adapter.setFormFilter(FormRecordFilter.values()[index]);
          adapter.resetRecords();
          adapter.notifyDataSetChanged();
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            invalidateOptionsMenu();
          }
        }
        @Override public void onNothingSelected(        AdapterView<?> arg0){
        }
      }
);
      filterSelect.setVisibility(View.VISIBLE);
    }
    if (filter != null) {
      adapter.setFormFilter(filter);
    }
    this.registerForContextMenu(listView);
    refreshView();
  }
 catch (  SessionUnavailableException sue) {
  }
}