Program: 7286
Project: 7286
Buggy source:
/** 
 * Build up the entries to display on the screen.
 * @param personCursor the URI for the contact being displayed
 */
private final void buildEntries(){
  final int numSections=mSections.size();
  for (int i=0; i < numSections; i++) {
    mSections.get(i).clear();
  }
  mRawContactIds.clear();
  mReadOnlySourcesCnt=0;
  mWritableSourcesCnt=0;
  mAllRestricted=true;
  mPrimaryPhoneUri=null;
  mWritableRawContactIds.clear();
  final Context context=this;
  final Sources sources=Sources.getInstance(context);
  if (mLookupUri != null) {
    for (    Entity entity : mEntities) {
      final ContentValues entValues=entity.getEntityValues();
      final String accountType=entValues.getAsString(RawContacts.ACCOUNT_TYPE);
      final long rawContactId=entValues.getAsLong(RawContacts._ID);
      final boolean isRestricted=entValues.getAsInteger(RawContacts.IS_RESTRICTED) != 0;
      if (!isRestricted)       mAllRestricted=false;
      if (!mRawContactIds.contains(rawContactId)) {
        mRawContactIds.add(rawContactId);
      }
      ContactsSource contactsSource=sources.getInflatedSource(accountType,ContactsSource.LEVEL_SUMMARY);
      if (contactsSource != null && contactsSource.readOnly) {
        mReadOnlySourcesCnt+=1;
      }
 else {
        mWritableSourcesCnt+=1;
        mWritableRawContactIds.add(rawContactId);
      }
      for (      NamedContentValues subValue : entity.getSubValues()) {
        final ContentValues entryValues=subValue.values;
        entryValues.put(Data.RAW_CONTACT_ID,rawContactId);
        final long dataId=entryValues.getAsLong(Data._ID);
        final String mimeType=entryValues.getAsString(Data.MIMETYPE);
        if (mimeType == null)         continue;
        final DataKind kind=sources.getKindOrFallback(accountType,mimeType,this,ContactsSource.LEVEL_MIMETYPES);
        if (kind == null)         continue;
        final ViewEntry entry=ViewEntry.fromValues(context,mimeType,kind,rawContactId,dataId,entryValues);
        final boolean hasData=!TextUtils.isEmpty(entry.data);
        final boolean isSuperPrimary=entryValues.getAsInteger(Data.IS_SUPER_PRIMARY) != 0;
        if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          mNumPhoneNumbers++;
          entry.intent=new Intent(Intent.ACTION_CALL_PRIVILEGED,Uri.fromParts(Constants.SCHEME_TEL,entry.data,null));
          entry.secondaryIntent=new Intent(Intent.ACTION_SENDTO,Uri.fromParts(Constants.SCHEME_SMSTO,entry.data,null));
          if (isSuperPrimary)           mPrimaryPhoneUri=entry.uri;
          entry.isPrimary=isSuperPrimary;
          mPhoneEntries.add(entry);
          Integer type;
          try {
            type=entryValues.getAsInteger(Phone.TYPE);
          }
 catch (          NullPointerException e) {
            type=CommonDataKinds.Phone.TYPE_HOME;
          }
          if (type == CommonDataKinds.Phone.TYPE_MOBILE || mShowSmsLinksForAllPhones) {
            if (kind.iconAltRes > 0) {
              entry.secondaryActionIcon=kind.iconAltRes;
            }
          }
        }
 else         if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.intent=new Intent(Intent.ACTION_SENDTO,Uri.fromParts(Constants.SCHEME_MAILTO,entry.data,null));
          entry.isPrimary=isSuperPrimary;
          mEmailEntries.add(entry);
          final DataStatus status=mStatuses.get(entry.id);
          if (status != null) {
            final String imMime=Im.CONTENT_ITEM_TYPE;
            final DataKind imKind=sources.getKindOrFallback(accountType,imMime,this,ContactsSource.LEVEL_MIMETYPES);
            final ViewEntry imEntry=ViewEntry.fromValues(context,imMime,imKind,rawContactId,dataId,entryValues);
            imEntry.intent=ContactsUtils.buildImIntent(entryValues);
            imEntry.applyStatus(status,false);
            mImEntries.add(imEntry);
          }
        }
 else         if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.maxLines=4;
          entry.intent=new Intent(Intent.ACTION_VIEW,entry.uri);
          Intent i=startNavigation(entry.data);
          if (i != null) {
            entry.secondaryIntent=i;
            if (kind.iconAltRes > 0) {
              entry.secondaryActionIcon=kind.iconAltRes;
            }
          }
          mPostalEntries.add(entry);
        }
 else         if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.intent=ContactsUtils.buildImIntent(entryValues);
          if (TextUtils.isEmpty(entry.label)) {
            entry.label=getString(R.string.chat).toLowerCase();
          }
          final DataStatus status=mStatuses.get(entry.id);
          if (status != null) {
            entry.applyStatus(status,false);
          }
          mImEntries.add(entry);
        }
 else         if (Organization.CONTENT_ITEM_TYPE.equals(mimeType) && (hasData || !TextUtils.isEmpty(entry.label))) {
          final boolean isNameRawContact=(mNameRawContactId == rawContactId);
          final boolean duplicatesTitle=isNameRawContact && mDisplayNameSource == DisplayNameSources.ORGANIZATION && (!hasData || TextUtils.isEmpty(entry.label));
          if (!duplicatesTitle) {
            entry.uri=null;
            if (TextUtils.isEmpty(entry.label)) {
              entry.label=entry.data;
              entry.data="String_Node_Str";
            }
            mOrganizationEntries.add(entry);
          }
        }
 else         if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          final boolean isNameRawContact=(mNameRawContactId == rawContactId);
          final boolean duplicatesTitle=isNameRawContact && mDisplayNameSource == DisplayNameSources.NICKNAME;
          if (!duplicatesTitle) {
            entry.uri=null;
            mNicknameEntries.add(entry);
          }
        }
 else         if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.uri=null;
          entry.maxLines=100;
          mOtherEntries.add(entry);
        }
 else         if (Website.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.uri=null;
          entry.maxLines=10;
          try {
            WebAddress webAddress=new WebAddress(entry.data);
            entry.intent=new Intent(Intent.ACTION_VIEW,Uri.parse(webAddress.toString()));
          }
 catch (          ParseException e) {
            Log.e(TAG,"String_Node_Str" + entry.data);
          }
          mOtherEntries.add(entry);
        }
 else {
          entry.intent=new Intent(Intent.ACTION_VIEW,entry.uri);
          final DataStatus status=mStatuses.get(entry.id);
          final boolean hasSocial=kind.actionBodySocial && status != null;
          if (hasSocial) {
            entry.applyStatus(status,true);
          }
          if (hasSocial || hasData) {
            mOtherEntries.add(entry);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Build up the entries to display on the screen.
 * @param personCursor the URI for the contact being displayed
 */
private final void buildEntries(){
  final int numSections=mSections.size();
  for (int i=0; i < numSections; i++) {
    mSections.get(i).clear();
  }
  mRawContactIds.clear();
  mReadOnlySourcesCnt=0;
  mWritableSourcesCnt=0;
  mAllRestricted=true;
  mPrimaryPhoneUri=null;
  mWritableRawContactIds.clear();
  final Context context=this;
  final Sources sources=Sources.getInstance(context);
  if (mLookupUri != null) {
    for (    Entity entity : mEntities) {
      final ContentValues entValues=entity.getEntityValues();
      final String accountType=entValues.getAsString(RawContacts.ACCOUNT_TYPE);
      final long rawContactId=entValues.getAsLong(RawContacts._ID);
      final boolean isRestricted=entValues.getAsInteger(RawContacts.IS_RESTRICTED) != 0;
      if (!isRestricted)       mAllRestricted=false;
      if (!mRawContactIds.contains(rawContactId)) {
        mRawContactIds.add(rawContactId);
      }
      ContactsSource contactsSource=sources.getInflatedSource(accountType,ContactsSource.LEVEL_SUMMARY);
      if (contactsSource != null && contactsSource.readOnly) {
        mReadOnlySourcesCnt+=1;
      }
 else {
        mWritableSourcesCnt+=1;
        mWritableRawContactIds.add(rawContactId);
      }
      for (      NamedContentValues subValue : entity.getSubValues()) {
        final ContentValues entryValues=subValue.values;
        entryValues.put(Data.RAW_CONTACT_ID,rawContactId);
        final long dataId=entryValues.getAsLong(Data._ID);
        final String mimeType=entryValues.getAsString(Data.MIMETYPE);
        if (mimeType == null)         continue;
        final DataKind kind=sources.getKindOrFallback(accountType,mimeType,this,ContactsSource.LEVEL_MIMETYPES);
        if (kind == null)         continue;
        final ViewEntry entry=ViewEntry.fromValues(context,mimeType,kind,rawContactId,dataId,entryValues);
        final boolean hasData=!TextUtils.isEmpty(entry.data);
        final boolean isSuperPrimary=entryValues.getAsInteger(Data.IS_SUPER_PRIMARY) != 0;
        if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          mNumPhoneNumbers++;
          entry.intent=new Intent(Intent.ACTION_CALL_PRIVILEGED,Uri.fromParts(Constants.SCHEME_TEL,entry.data,null));
          entry.secondaryIntent=new Intent(Intent.ACTION_SENDTO,Uri.fromParts(Constants.SCHEME_SMSTO,entry.data,null));
          if (isSuperPrimary)           mPrimaryPhoneUri=entry.uri;
          entry.isPrimary=isSuperPrimary;
          mPhoneEntries.add(entry);
          Integer type=entryValues.getAsInteger(Phone.TYPE);
          if (type.intValue() == (CommonDataKinds.Phone.TYPE_MOBILE) || mShowSmsLinksForAllPhones) {
            if (kind.iconAltRes > 0) {
              entry.secondaryActionIcon=kind.iconAltRes;
            }
          }
        }
 else         if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.intent=new Intent(Intent.ACTION_SENDTO,Uri.fromParts(Constants.SCHEME_MAILTO,entry.data,null));
          entry.isPrimary=isSuperPrimary;
          mEmailEntries.add(entry);
          final DataStatus status=mStatuses.get(entry.id);
          if (status != null) {
            final String imMime=Im.CONTENT_ITEM_TYPE;
            final DataKind imKind=sources.getKindOrFallback(accountType,imMime,this,ContactsSource.LEVEL_MIMETYPES);
            final ViewEntry imEntry=ViewEntry.fromValues(context,imMime,imKind,rawContactId,dataId,entryValues);
            imEntry.intent=ContactsUtils.buildImIntent(entryValues);
            imEntry.applyStatus(status,false);
            mImEntries.add(imEntry);
          }
        }
 else         if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.maxLines=4;
          entry.intent=new Intent(Intent.ACTION_VIEW,entry.uri);
          Intent i=startNavigation(entry.data);
          if (i != null) {
            entry.secondaryIntent=i;
            if (kind.iconAltRes > 0) {
              entry.secondaryActionIcon=kind.iconAltRes;
            }
          }
          mPostalEntries.add(entry);
        }
 else         if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.intent=ContactsUtils.buildImIntent(entryValues);
          if (TextUtils.isEmpty(entry.label)) {
            entry.label=getString(R.string.chat).toLowerCase();
          }
          final DataStatus status=mStatuses.get(entry.id);
          if (status != null) {
            entry.applyStatus(status,false);
          }
          mImEntries.add(entry);
        }
 else         if (Organization.CONTENT_ITEM_TYPE.equals(mimeType) && (hasData || !TextUtils.isEmpty(entry.label))) {
          final boolean isNameRawContact=(mNameRawContactId == rawContactId);
          final boolean duplicatesTitle=isNameRawContact && mDisplayNameSource == DisplayNameSources.ORGANIZATION && (!hasData || TextUtils.isEmpty(entry.label));
          if (!duplicatesTitle) {
            entry.uri=null;
            if (TextUtils.isEmpty(entry.label)) {
              entry.label=entry.data;
              entry.data="String_Node_Str";
            }
            mOrganizationEntries.add(entry);
          }
        }
 else         if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          final boolean isNameRawContact=(mNameRawContactId == rawContactId);
          final boolean duplicatesTitle=isNameRawContact && mDisplayNameSource == DisplayNameSources.NICKNAME;
          if (!duplicatesTitle) {
            entry.uri=null;
            mNicknameEntries.add(entry);
          }
        }
 else         if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.uri=null;
          entry.maxLines=100;
          mOtherEntries.add(entry);
        }
 else         if (Website.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
          entry.uri=null;
          entry.maxLines=10;
          try {
            WebAddress webAddress=new WebAddress(entry.data);
            entry.intent=new Intent(Intent.ACTION_VIEW,Uri.parse(webAddress.toString()));
          }
 catch (          ParseException e) {
            Log.e(TAG,"String_Node_Str" + entry.data);
          }
          mOtherEntries.add(entry);
        }
 else {
          entry.intent=new Intent(Intent.ACTION_VIEW,entry.uri);
          final DataStatus status=mStatuses.get(entry.id);
          final boolean hasSocial=kind.actionBodySocial && status != null;
          if (hasSocial) {
            entry.applyStatus(status,true);
          }
          if (hasSocial || hasData) {
            mOtherEntries.add(entry);
          }
        }
      }
    }
  }
}