Program: 187437
Project: 187437
Buggy source:
public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.importcontacts);
  confirm=(Button)findViewById(R.id.confirm);
  importList=(ListView)findViewById(R.id.import_contact_list);
  ContentResolver cr=getContentResolver();
  tc=new ArrayList<TrustedContact>();
  ArrayList<String> number;
  String name;
  String columnsN[]=new String[]{Phone.NUMBER};
  String columnsC[]=new String[]{Contacts._ID,Contacts.DISPLAY_NAME,Contacts.HAS_PHONE_NUMBER};
  Uri mContacts=ContactsContract.Contacts.CONTENT_URI;
  Cursor cur=managedQuery(mContacts,columnsC,null,null,Contacts.DISPLAY_NAME);
  if (cur.moveToFirst()) {
    do {
      number=new ArrayList<String>();
      name=cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
      String id=cur.getString(cur.getColumnIndex(Contacts._ID));
      if (cur.getString(cur.getColumnIndex(Contacts.HAS_PHONE_NUMBER)).equalsIgnoreCase("String_Node_Str")) {
        Cursor pCur=cr.query(Phone.CONTENT_URI,columnsN,Phone.CONTACT_ID + "String_Node_Str",new String[]{id},null);
        if (pCur.moveToFirst()) {
          do {
            number.add(pCur.getString(pCur.getColumnIndex(Phone.NUMBER)));
          }
 while (pCur.moveToNext());
        }
        pCur.close();
      }
      if (number != null) {
        if (!Prephase2Activity.dba.inDatabase(number)) {
          tc.add(new TrustedContact(name,-1,number));
        }
      }
      number=null;
    }
 while (cur.moveToNext());
  }
  if (tc != null && tc.size() > 0) {
    disable=false;
    importList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,getNames()));
    importList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  }
 else {
    disable=true;
    importList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,getNames()));
  }
  confirm.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View v){
      if (!disable) {
        for (int i=0; i < tc.size(); i++) {
          if (tc.get(i).getVerified() == 0) {
            Prephase2Activity.dba.addRow(tc.get(i));
          }
        }
        finish();
      }
    }
  }
);
  importList.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      if (!disable) {
        change(position);
      }
    }
  }
);
}

Fixed version (ground truth):
public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.importcontacts);
  confirm=(Button)findViewById(R.id.confirm);
  importList=(ListView)findViewById(R.id.import_contact_list);
  ContentResolver cr=getContentResolver();
  tc=new ArrayList<TrustedContact>();
  ArrayList<String> number;
  String name;
  String columnsN[]=new String[]{Phone.NUMBER};
  String columnsC[]=new String[]{Contacts._ID,Contacts.DISPLAY_NAME,Contacts.HAS_PHONE_NUMBER};
  Uri mContacts=ContactsContract.Contacts.CONTENT_URI;
  Cursor cur=managedQuery(mContacts,columnsC,null,null,Contacts.DISPLAY_NAME);
  if (cur.moveToFirst()) {
    do {
      number=new ArrayList<String>();
      name=cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
      String id=cur.getString(cur.getColumnIndex(Contacts._ID));
      if (cur.getString(cur.getColumnIndex(Contacts.HAS_PHONE_NUMBER)).equalsIgnoreCase("String_Node_Str")) {
        Cursor pCur=cr.query(Phone.CONTENT_URI,columnsN,Phone.CONTACT_ID + "String_Node_Str",new String[]{id},null);
        if (pCur.moveToFirst()) {
          do {
            number.add(ContactRetriever.format(pCur.getString(pCur.getColumnIndex(Phone.NUMBER))));
          }
 while (pCur.moveToNext());
        }
        pCur.close();
      }
      if (number != null) {
        if (!Prephase2Activity.dba.inDatabase(number)) {
          tc.add(new TrustedContact(name,-1,number));
        }
      }
      number=null;
    }
 while (cur.moveToNext());
  }
  if (tc != null && tc.size() > 0) {
    disable=false;
    importList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,getNames()));
    importList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  }
 else {
    disable=true;
    importList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,getNames()));
  }
  confirm.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View v){
      if (!disable) {
        for (int i=0; i < tc.size(); i++) {
          if (tc.get(i).getVerified() == 0) {
            Prephase2Activity.dba.addRow(tc.get(i));
          }
        }
        finish();
      }
    }
  }
);
  importList.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      if (!disable) {
        change(position);
      }
    }
  }
);
}