Program: 187410
Project: 187410
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);
  tc=new ArrayList<TrustedContact>();
  ArrayList<Number> number;
  String name;
  String id;
  Uri mContacts=ContactsContract.Contacts.CONTENT_URI;
  Cursor cur=managedQuery(mContacts,new String[]{Contacts._ID,Contacts.DISPLAY_NAME,Contacts.HAS_PHONE_NUMBER},null,null,Contacts.DISPLAY_NAME);
  inDb=new ArrayList<Boolean>();
  if (cur.moveToFirst()) {
    do {
      number=new ArrayList<Number>();
      name=cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
      id=cur.getString(cur.getColumnIndex(Contacts._ID));
      if (cur.getString(cur.getColumnIndex(Contacts.HAS_PHONE_NUMBER)).equalsIgnoreCase("String_Node_Str")) {
        Cursor pCur=getContentResolver().query(Phone.CONTENT_URI,new String[]{Phone.NUMBER,Phone.TYPE},Phone.CONTACT_ID + "String_Node_Str",new String[]{id},null);
        if (pCur.moveToFirst()) {
          do {
            String numb=(pCur.getString(pCur.getColumnIndex(Phone.NUMBER)));
            int type=pCur.getInt(pCur.getColumnIndex(Phone.TYPE));
            Uri uriSMSURI=Uri.parse("String_Node_Str");
            Cursor mCur=getContentResolver().query(uriSMSURI,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{ContactRetriever.format(numb),"String_Node_Str" + ContactRetriever.format(numb),"String_Node_Str" + ContactRetriever.format(numb)},"String_Node_Str");
            if (mCur.moveToFirst()) {
              number.add(new Number(ContactRetriever.format(numb),type,mCur.getString(mCur.getColumnIndex("String_Node_Str")),mCur.getLong(mCur.getColumnIndex("String_Node_Str"))));
            }
 else {
              number.add(new Number(ContactRetriever.format(numb),type));
            }
          }
 while (pCur.moveToNext());
        }
        pCur.close();
      }
      if (number != null) {
        if (!MessageService.dba.inDatabase(number)) {
          tc.add(new TrustedContact(name,number));
          inDb.add(false);
        }
      }
      number=null;
    }
 while (cur.moveToNext());
  }
  Uri uriSMSURI=Uri.parse("String_Node_Str");
  Cursor convCur=getContentResolver().query(uriSMSURI,new String[]{"String_Node_Str","String_Node_Str"},null,null,"String_Node_Str");
  Number newNumber;
  while (convCur.moveToNext()) {
    id=convCur.getString(convCur.getColumnIndex("String_Node_Str"));
    newNumber=new Number(null,convCur.getString(convCur.getColumnIndex("String_Node_Str")));
    Cursor nCur=getContentResolver().query(Uri.parse("String_Node_Str"),new String[]{"String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{id},"String_Node_Str");
    if (nCur.moveToFirst()) {
      newNumber.setNumber(ContactRetriever.format(nCur.getString(nCur.getColumnIndex("String_Node_Str"))));
      newNumber.setDate(nCur.getLong(nCur.getColumnIndex("String_Node_Str")));
    }
 else {
      Cursor sCur=getContentResolver().query(Uri.parse("String_Node_Str"),new String[]{"String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{id},"String_Node_Str");
      if (sCur.moveToFirst()) {
        newNumber.setNumber(ContactRetriever.format(sCur.getString(sCur.getColumnIndex("String_Node_Str"))));
        newNumber.setDate(sCur.getLong(sCur.getColumnIndex("String_Node_Str")));
      }
    }
    if (!TrustedContact.isNumberUsed(tc,newNumber.getNumber()) && !MessageService.dba.inDatabase(newNumber.getNumber())) {
      tc.add(new TrustedContact(newNumber));
      inDb.add(false);
    }
  }
  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 (inDb.get(i)) {
            MessageService.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);
  tc=new ArrayList<TrustedContact>();
  ArrayList<Number> number;
  String name;
  String id;
  Uri mContacts=ContactsContract.Contacts.CONTENT_URI;
  Cursor cur=managedQuery(mContacts,new String[]{Contacts._ID,Contacts.DISPLAY_NAME,Contacts.HAS_PHONE_NUMBER},null,null,Contacts.DISPLAY_NAME);
  inDb=new ArrayList<Boolean>();
  if (cur.moveToFirst()) {
    do {
      number=new ArrayList<Number>();
      name=cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
      id=cur.getString(cur.getColumnIndex(Contacts._ID));
      if (cur.getString(cur.getColumnIndex(Contacts.HAS_PHONE_NUMBER)).equalsIgnoreCase("String_Node_Str")) {
        Cursor pCur=getContentResolver().query(Phone.CONTENT_URI,new String[]{Phone.NUMBER,Phone.TYPE},Phone.CONTACT_ID + "String_Node_Str",new String[]{id},null);
        if (pCur.moveToFirst()) {
          do {
            String numb=(pCur.getString(pCur.getColumnIndex(Phone.NUMBER)));
            int type=pCur.getInt(pCur.getColumnIndex(Phone.TYPE));
            Uri uriSMSURI=Uri.parse("String_Node_Str");
            Cursor mCur=getContentResolver().query(uriSMSURI,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{ContactRetriever.format(numb),"String_Node_Str" + ContactRetriever.format(numb),"String_Node_Str" + ContactRetriever.format(numb)},"String_Node_Str");
            if (mCur.moveToFirst()) {
              number.add(new Number(ContactRetriever.format(numb),type,mCur.getString(mCur.getColumnIndex("String_Node_Str")),mCur.getLong(mCur.getColumnIndex("String_Node_Str"))));
            }
 else {
              number.add(new Number(ContactRetriever.format(numb),type));
            }
          }
 while (pCur.moveToNext());
        }
        pCur.close();
      }
      if (number != null) {
        if (!MessageService.dba.inDatabase(number)) {
          tc.add(new TrustedContact(name,number));
          inDb.add(false);
        }
      }
      number=null;
    }
 while (cur.moveToNext());
  }
  Uri uriSMSURI=Uri.parse("String_Node_Str");
  Cursor convCur=getContentResolver().query(uriSMSURI,new String[]{"String_Node_Str","String_Node_Str"},null,null,"String_Node_Str");
  Number newNumber;
  while (convCur.moveToNext()) {
    id=convCur.getString(convCur.getColumnIndex("String_Node_Str"));
    newNumber=new Number(convCur.getString(convCur.getColumnIndex("String_Node_Str")));
    Cursor nCur=getContentResolver().query(Uri.parse("String_Node_Str"),new String[]{"String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{id},"String_Node_Str");
    if (nCur.moveToFirst()) {
      newNumber.setNumber(ContactRetriever.format(nCur.getString(nCur.getColumnIndex("String_Node_Str"))));
      newNumber.setDate(nCur.getLong(nCur.getColumnIndex("String_Node_Str")));
    }
 else {
      Cursor sCur=getContentResolver().query(Uri.parse("String_Node_Str"),new String[]{"String_Node_Str","String_Node_Str"},"String_Node_Str",new String[]{id},"String_Node_Str");
      if (sCur.moveToFirst()) {
        newNumber.setNumber(ContactRetriever.format(sCur.getString(sCur.getColumnIndex("String_Node_Str"))));
        newNumber.setDate(sCur.getLong(sCur.getColumnIndex("String_Node_Str")));
      }
    }
    if (!TrustedContact.isNumberUsed(tc,newNumber.getNumber()) && !MessageService.dba.inDatabase(newNumber.getNumber())) {
      tc.add(new TrustedContact(newNumber));
      inDb.add(false);
    }
  }
  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 (inDb.get(i)) {
            MessageService.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);
      }
    }
  }
);
}