Program: 43200
Project: 43200
Buggy source:
private void appendStructuredNamesInternal(final StringBuilder builder,final List<ContentValues> contentValuesList){
  for (  ContentValues contentValues : contentValuesList) {
    final String familyName=contentValues.getAsString(StructuredName.FAMILY_NAME);
    final String middleName=contentValues.getAsString(StructuredName.MIDDLE_NAME);
    final String givenName=contentValues.getAsString(StructuredName.GIVEN_NAME);
    final String prefix=contentValues.getAsString(StructuredName.PREFIX);
    final String suffix=contentValues.getAsString(StructuredName.SUFFIX);
    final String displayName=contentValues.getAsString(StructuredName.DISPLAY_NAME);
    if (!TextUtils.isEmpty(familyName) || !TextUtils.isEmpty(givenName)) {
      final String encodedFamily=escapeCharacters(familyName);
      final String encodedGiven=escapeCharacters(givenName);
      final String encodedMiddle=escapeCharacters(middleName);
      final String encodedPrefix=escapeCharacters(prefix);
      final String encodedSuffix=escapeCharacters(suffix);
      builder.append(VCARD_PROPERTY_NAME);
      if (!(VCardUtils.containsOnlyAscii(familyName) && VCardUtils.containsOnlyAscii(givenName) && VCardUtils.containsOnlyAscii(middleName)&& VCardUtils.containsOnlyAscii(prefix)&& VCardUtils.containsOnlyAscii(suffix))) {
        builder.append(VCARD_ATTR_SEPARATOR);
        builder.append(mVCardAttributeCharset);
      }
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(encodedFamily);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedGiven);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedMiddle);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedPrefix);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedSuffix);
      builder.append(VCARD_COL_SEPARATOR);
      final String encodedFullname=VCardUtils.constructNameFromElements(VCardConfig.getNameOrderType(mVCardType),encodedFamily,encodedMiddle,encodedGiven,encodedPrefix,encodedSuffix);
      builder.append(VCARD_PROPERTY_FULL_NAME);
      builder.append(VCARD_ATTR_SEPARATOR);
      if (!VCardUtils.containsOnlyAscii(encodedFullname)) {
        builder.append(mVCardAttributeCharset);
        builder.append(VCARD_DATA_SEPARATOR);
      }
      builder.append(encodedFullname);
      builder.append(VCARD_COL_SEPARATOR);
    }
 else     if (!TextUtils.isEmpty(displayName)) {
      builder.append(VCARD_PROPERTY_NAME);
      builder.append(VCARD_ATTR_SEPARATOR);
      builder.append(mVCardAttributeCharset);
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(escapeCharacters(displayName));
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_COL_SEPARATOR);
    }
 else     if (mIsDoCoMo) {
      appendVCardLine(builder,VCARD_PROPERTY_NAME,"String_Node_Str");
    }
    String phoneticFamilyName=contentValues.getAsString(StructuredName.PHONETIC_FAMILY_NAME);
    String phoneticMiddleName=contentValues.getAsString(StructuredName.PHONETIC_MIDDLE_NAME);
    String phoneticGivenName=contentValues.getAsString(StructuredName.PHONETIC_GIVEN_NAME);
    if (!(TextUtils.isEmpty(phoneticFamilyName) && TextUtils.isEmpty(phoneticMiddleName) && TextUtils.isEmpty(phoneticGivenName))) {
      if (mIsJapaneseMobilePhone) {
        phoneticFamilyName=VCardUtils.toHalfWidthString(phoneticFamilyName);
        phoneticMiddleName=VCardUtils.toHalfWidthString(phoneticMiddleName);
        phoneticGivenName=VCardUtils.toHalfWidthString(phoneticGivenName);
      }
      if (mIsV30) {
        final String sortString=VCardUtils.constructNameFromElements(mVCardType,phoneticFamilyName,phoneticMiddleName,phoneticGivenName);
        builder.append(VCARD_PROPERTY_SORT_STRING);
        if (!VCardUtils.containsOnlyAscii(sortString)) {
          builder.append(VCARD_ATTR_SEPARATOR);
          builder.append(mVCardAttributeCharset);
        }
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(sortString);
        builder.append(VCARD_COL_SEPARATOR);
      }
 else {
        builder.append(VCARD_PROPERTY_SOUND);
        builder.append(VCARD_ATTR_SEPARATOR);
        builder.append(Constants.ATTR_TYPE_X_IRMC_N);
        builder.append(VCARD_ATTR_SEPARATOR);
        if (!(VCardUtils.containsOnlyAscii(phoneticFamilyName) && VCardUtils.containsOnlyAscii(phoneticMiddleName) && VCardUtils.containsOnlyAscii(phoneticGivenName))) {
          builder.append(mVCardAttributeCharset);
          builder.append(VCARD_DATA_SEPARATOR);
        }
        builder.append(escapeCharacters(phoneticFamilyName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(escapeCharacters(phoneticMiddleName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(escapeCharacters(phoneticGivenName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(VCARD_COL_SEPARATOR);
        if (mUsesAndroidProperty) {
          final String phoneticName=VCardUtils.constructNameFromElements(mVCardType,phoneticFamilyName,phoneticMiddleName,phoneticGivenName);
          builder.append(VCARD_PROPERTY_X_PHONETIC_NAME);
          if (!VCardUtils.containsOnlyAscii(phoneticName)) {
            builder.append(VCARD_ATTR_SEPARATOR);
            builder.append(mVCardAttributeCharset);
          }
          builder.append(VCARD_DATA_SEPARATOR);
          builder.append(phoneticName);
          builder.append(VCARD_COL_SEPARATOR);
        }
      }
    }
 else     if (mIsDoCoMo) {
      builder.append(VCARD_PROPERTY_SOUND);
      builder.append(VCARD_ATTR_SEPARATOR);
      builder.append(Constants.ATTR_TYPE_X_IRMC_N);
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_COL_SEPARATOR);
    }
    if (mUsesDefactProperty) {
      if (!TextUtils.isEmpty(phoneticGivenName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_FIRST_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticGivenName);
        builder.append(VCARD_COL_SEPARATOR);
      }
      if (!TextUtils.isEmpty(phoneticMiddleName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_MIDDLE_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticMiddleName);
        builder.append(VCARD_COL_SEPARATOR);
      }
      if (!TextUtils.isEmpty(phoneticFamilyName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_LAST_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticFamilyName);
        builder.append(VCARD_COL_SEPARATOR);
      }
    }
  }
}

Fixed version (ground truth):
private void appendStructuredNamesInternal(final StringBuilder builder,final List<ContentValues> contentValuesList){
  for (  ContentValues contentValues : contentValuesList) {
    final String familyName=contentValues.getAsString(StructuredName.FAMILY_NAME);
    final String middleName=contentValues.getAsString(StructuredName.MIDDLE_NAME);
    final String givenName=contentValues.getAsString(StructuredName.GIVEN_NAME);
    final String prefix=contentValues.getAsString(StructuredName.PREFIX);
    final String suffix=contentValues.getAsString(StructuredName.SUFFIX);
    final String displayName=contentValues.getAsString(StructuredName.DISPLAY_NAME);
    if (!TextUtils.isEmpty(familyName) || !TextUtils.isEmpty(givenName)) {
      final String encodedFamily=escapeCharacters(familyName);
      final String encodedGiven=escapeCharacters(givenName);
      final String encodedMiddle=escapeCharacters(middleName);
      final String encodedPrefix=escapeCharacters(prefix);
      final String encodedSuffix=escapeCharacters(suffix);
      builder.append(VCARD_PROPERTY_NAME);
      if (!(VCardUtils.containsOnlyAscii(familyName) && VCardUtils.containsOnlyAscii(givenName) && VCardUtils.containsOnlyAscii(middleName)&& VCardUtils.containsOnlyAscii(prefix)&& VCardUtils.containsOnlyAscii(suffix))) {
        builder.append(VCARD_ATTR_SEPARATOR);
        builder.append(mVCardAttributeCharset);
      }
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(encodedFamily);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedGiven);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedMiddle);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedPrefix);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(encodedSuffix);
      builder.append(VCARD_COL_SEPARATOR);
      final String encodedFullname=VCardUtils.constructNameFromElements(VCardConfig.getNameOrderType(mVCardType),encodedFamily,encodedMiddle,encodedGiven,encodedPrefix,encodedSuffix);
      builder.append(VCARD_PROPERTY_FULL_NAME);
      if (!VCardUtils.containsOnlyAscii(encodedFullname)) {
        builder.append(VCARD_ATTR_SEPARATOR);
        builder.append(mVCardAttributeCharset);
      }
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(encodedFullname);
      builder.append(VCARD_COL_SEPARATOR);
    }
 else     if (!TextUtils.isEmpty(displayName)) {
      builder.append(VCARD_PROPERTY_NAME);
      builder.append(VCARD_ATTR_SEPARATOR);
      builder.append(mVCardAttributeCharset);
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(escapeCharacters(displayName));
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_COL_SEPARATOR);
    }
 else     if (mIsDoCoMo) {
      appendVCardLine(builder,VCARD_PROPERTY_NAME,"String_Node_Str");
    }
    String phoneticFamilyName=contentValues.getAsString(StructuredName.PHONETIC_FAMILY_NAME);
    String phoneticMiddleName=contentValues.getAsString(StructuredName.PHONETIC_MIDDLE_NAME);
    String phoneticGivenName=contentValues.getAsString(StructuredName.PHONETIC_GIVEN_NAME);
    if (!(TextUtils.isEmpty(phoneticFamilyName) && TextUtils.isEmpty(phoneticMiddleName) && TextUtils.isEmpty(phoneticGivenName))) {
      if (mIsJapaneseMobilePhone) {
        phoneticFamilyName=VCardUtils.toHalfWidthString(phoneticFamilyName);
        phoneticMiddleName=VCardUtils.toHalfWidthString(phoneticMiddleName);
        phoneticGivenName=VCardUtils.toHalfWidthString(phoneticGivenName);
      }
      if (mIsV30) {
        final String sortString=VCardUtils.constructNameFromElements(mVCardType,phoneticFamilyName,phoneticMiddleName,phoneticGivenName);
        builder.append(VCARD_PROPERTY_SORT_STRING);
        if (!VCardUtils.containsOnlyAscii(sortString)) {
          builder.append(VCARD_ATTR_SEPARATOR);
          builder.append(mVCardAttributeCharset);
        }
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(sortString);
        builder.append(VCARD_COL_SEPARATOR);
      }
 else {
        builder.append(VCARD_PROPERTY_SOUND);
        builder.append(VCARD_ATTR_SEPARATOR);
        builder.append(Constants.ATTR_TYPE_X_IRMC_N);
        builder.append(VCARD_ATTR_SEPARATOR);
        if (!(VCardUtils.containsOnlyAscii(phoneticFamilyName) && VCardUtils.containsOnlyAscii(phoneticMiddleName) && VCardUtils.containsOnlyAscii(phoneticGivenName))) {
          builder.append(mVCardAttributeCharset);
          builder.append(VCARD_DATA_SEPARATOR);
        }
        builder.append(escapeCharacters(phoneticFamilyName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(escapeCharacters(phoneticMiddleName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(escapeCharacters(phoneticGivenName));
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(VCARD_ITEM_SEPARATOR);
        builder.append(VCARD_COL_SEPARATOR);
        if (mUsesAndroidProperty) {
          final String phoneticName=VCardUtils.constructNameFromElements(mVCardType,phoneticFamilyName,phoneticMiddleName,phoneticGivenName);
          builder.append(VCARD_PROPERTY_X_PHONETIC_NAME);
          if (!VCardUtils.containsOnlyAscii(phoneticName)) {
            builder.append(VCARD_ATTR_SEPARATOR);
            builder.append(mVCardAttributeCharset);
          }
          builder.append(VCARD_DATA_SEPARATOR);
          builder.append(phoneticName);
          builder.append(VCARD_COL_SEPARATOR);
        }
      }
    }
 else     if (mIsDoCoMo) {
      builder.append(VCARD_PROPERTY_SOUND);
      builder.append(VCARD_ATTR_SEPARATOR);
      builder.append(Constants.ATTR_TYPE_X_IRMC_N);
      builder.append(VCARD_DATA_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_ITEM_SEPARATOR);
      builder.append(VCARD_COL_SEPARATOR);
    }
    if (mUsesDefactProperty) {
      if (!TextUtils.isEmpty(phoneticGivenName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_FIRST_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticGivenName);
        builder.append(VCARD_COL_SEPARATOR);
      }
      if (!TextUtils.isEmpty(phoneticMiddleName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_MIDDLE_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticMiddleName);
        builder.append(VCARD_COL_SEPARATOR);
      }
      if (!TextUtils.isEmpty(phoneticFamilyName)) {
        builder.append(VCARD_PROPERTY_X_PHONETIC_LAST_NAME);
        builder.append(VCARD_DATA_SEPARATOR);
        builder.append(phoneticFamilyName);
        builder.append(VCARD_COL_SEPARATOR);
      }
    }
  }
}