Program: 33866
Project: 33866
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_search_results);
  resultsList=(ListView)findViewById(R.id.results);
  getActionBar().setDisplayHomeAsUpEnabled(true);
  getActionBar().setTitle("String_Node_Str");
  String query=getIntent().getStringExtra(QUERY);
  int resultsType=getIntent().getIntExtra(RESULTS_TYPE,-1);
  if (query == null || resultsType == -1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  String finalQuery=Utilities.getPreparedQueryForSearch(query);
  ArrayList<ListItem> listItems=new ArrayList<>();
switch (resultsType) {
case TEAM_RESULTS:
    getActionBar().setTitle(String.format(getString(R.string.teams_matching),query));
  Cursor teamQueryResults=Database.getInstance(this).getMatchesForTeamQuery(finalQuery);
if (teamQueryResults != null && teamQueryResults.moveToFirst()) {
  teamQueryResults.moveToPosition(-1);
  while (teamQueryResults.moveToNext()) {
    String key=teamQueryResults.getString(teamQueryResults.getColumnIndex(Database.SearchTeam.KEY));
    Team team=Database.getInstance(this).getTeam(key);
    TeamListElement element=new TeamListElement(team);
    listItems.add(element);
  }
}
 else {
  listItems.add(new EmptyListElement(getString(R.string.no_teams_found)));
}
break;
case EVENT_RESULTS:
getActionBar().setTitle(String.format(getString(R.string.events_matching),query));
Cursor eventQueryResults=Database.getInstance(this).getMatchesForEventQuery(finalQuery);
if (eventQueryResults != null && eventQueryResults.moveToFirst()) {
eventQueryResults.moveToPosition(-1);
while (eventQueryResults.moveToNext()) {
String key=eventQueryResults.getString(eventQueryResults.getColumnIndex(Database.SearchEvent.KEY));
Event event=Database.getInstance(this).getEvent(key);
EventListElement element=new EventListElement(event);
listItems.add(element);
}
}
 else {
listItems.add(new EmptyListElement(getString(R.string.no_events_found)));
}
break;
}
ListViewAdapter adapter=new ListViewAdapter(this,listItems);
resultsList.setAdapter(adapter);
resultsList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override public void onItemClick(AdapterView<?> adapterView,View view,int position,long id){
ListViewAdapter adapter=(ListViewAdapter)adapterView.getAdapter();
ListItem clickedItem=adapter.getItem(position);
if (clickedItem instanceof TeamListElement) {
String teamKey=((ListElement)clickedItem).getKey();
Intent i=new Intent(MoreSearchResultsActivity.this,ViewTeamActivity.class);
i.putExtra(ViewTeamActivity.TEAM_KEY,teamKey);
startActivity(i);
}
 else if (clickedItem instanceof EventListElement) {
String eventKey=((ListElement)clickedItem).getKey();
Intent intent=ViewEventActivity.newInstance(MoreSearchResultsActivity.this,eventKey);
startActivity(intent);
}
}
}
);
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_search_results);
  resultsList=(ListView)findViewById(R.id.results);
  getActionBar().setDisplayHomeAsUpEnabled(true);
  getActionBar().setTitle("String_Node_Str");
  String query=getIntent().getStringExtra(QUERY);
  int resultsType=getIntent().getIntExtra(RESULTS_TYPE,-1);
  if (query == null || resultsType == -1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  String finalQuery=Utilities.getPreparedQueryForSearch(query);
  ArrayList<ListItem> listItems=new ArrayList<>();
switch (resultsType) {
case TEAM_RESULTS:
    getActionBar().setTitle(String.format(getString(R.string.teams_matching),query));
  Cursor teamQueryResults=Database.getInstance(this).getMatchesForTeamQuery(finalQuery);
if (teamQueryResults != null && teamQueryResults.moveToFirst()) {
  teamQueryResults.moveToPosition(-1);
  while (teamQueryResults.moveToNext()) {
    String key=teamQueryResults.getString(teamQueryResults.getColumnIndex(Database.SearchTeam.KEY));
    Team team=Database.getInstance(this).getTeam(key);
    TeamListElement element=new TeamListElement(team);
    listItems.add(element);
  }
  teamQueryResults.close();
}
 else {
  listItems.add(new EmptyListElement(getString(R.string.no_teams_found)));
}
break;
case EVENT_RESULTS:
getActionBar().setTitle(String.format(getString(R.string.events_matching),query));
Cursor eventQueryResults=Database.getInstance(this).getMatchesForEventQuery(finalQuery);
if (eventQueryResults != null && eventQueryResults.moveToFirst()) {
eventQueryResults.moveToPosition(-1);
while (eventQueryResults.moveToNext()) {
String key=eventQueryResults.getString(eventQueryResults.getColumnIndex(Database.SearchEvent.KEY));
Event event=Database.getInstance(this).getEvent(key);
EventListElement element=new EventListElement(event);
listItems.add(element);
}
eventQueryResults.close();
}
 else {
listItems.add(new EmptyListElement(getString(R.string.no_events_found)));
}
break;
}
ListViewAdapter adapter=new ListViewAdapter(this,listItems);
resultsList.setAdapter(adapter);
resultsList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override public void onItemClick(AdapterView<?> adapterView,View view,int position,long id){
ListViewAdapter adapter=(ListViewAdapter)adapterView.getAdapter();
ListItem clickedItem=adapter.getItem(position);
if (clickedItem instanceof TeamListElement) {
String teamKey=((ListElement)clickedItem).getKey();
Intent i=new Intent(MoreSearchResultsActivity.this,ViewTeamActivity.class);
i.putExtra(ViewTeamActivity.TEAM_KEY,teamKey);
startActivity(i);
}
 else if (clickedItem instanceof EventListElement) {
String eventKey=((ListElement)clickedItem).getKey();
Intent intent=ViewEventActivity.newInstance(MoreSearchResultsActivity.this,eventKey);
startActivity(intent);
}
}
}
);
}