Program: 8228
Project: 8228
Buggy source:
private KeyIdResult returnKeyIdsFromEmails(Intent data,String[] encryptionUserIds,boolean isOpportunistic){
  boolean noUserIdsCheck=(encryptionUserIds == null || encryptionUserIds.length == 0);
  boolean missingUserIdsCheck=false;
  boolean duplicateUserIdsCheck=false;
  HashSet<Long> keyIds=new HashSet<>();
  ArrayList<String> missingEmails=new ArrayList<>();
  ArrayList<String> duplicateEmails=new ArrayList<>();
  if (!noUserIdsCheck) {
    for (    String rawUserId : encryptionUserIds) {
      OpenPgpUtils.UserId userId=KeyRing.splitUserId(rawUserId);
      String email=userId.email != null ? userId.email : rawUserId;
      Uri uri=KeyRings.buildUnifiedKeyRingsFindByEmailUri(email);
      Cursor cursor=getContentResolver().query(uri,KEY_SEARCH_PROJECTION,KEY_SEARCH_WHERE,null,null);
      try {
        if (cursor != null && cursor.moveToFirst()) {
          long id=cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID));
          keyIds.add(id);
        }
 else {
          missingUserIdsCheck=true;
          missingEmails.add(email);
          Log.d(Constants.TAG,"String_Node_Str");
        }
        if (cursor != null && cursor.moveToNext()) {
          duplicateUserIdsCheck=true;
          duplicateEmails.add(email);
          long id=cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID));
          keyIds.add(id);
          Log.d(Constants.TAG,"String_Node_Str");
        }
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
    }
  }
  if (isOpportunistic && (noUserIdsCheck || missingUserIdsCheck)) {
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_ERROR,new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS,"String_Node_Str"));
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR);
    return new KeyIdResult(result);
  }
  if (noUserIdsCheck || missingUserIdsCheck || duplicateUserIdsCheck) {
    long[] keyIdsArray=getUnboxedLongArray(keyIds);
    ApiPendingIntentFactory piFactory=new ApiPendingIntentFactory(getBaseContext());
    PendingIntent pi=piFactory.createSelectPublicKeyPendingIntent(data,keyIdsArray,missingEmails,duplicateEmails,noUserIdsCheck);
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_INTENT,pi);
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
    return new KeyIdResult(result);
  }
  if (keyIds.isEmpty()) {
    Log.e(Constants.TAG,"String_Node_Str");
  }
  return new KeyIdResult(keyIds);
}

Fixed version (ground truth):
private KeyIdResult returnKeyIdsFromEmails(Intent data,String[] encryptionUserIds,boolean isOpportunistic){
  boolean hasUserIds=(encryptionUserIds != null && encryptionUserIds.length > 0);
  HashSet<Long> keyIds=new HashSet<>();
  ArrayList<String> missingEmails=new ArrayList<>();
  ArrayList<String> duplicateEmails=new ArrayList<>();
  if (hasUserIds) {
    for (    String rawUserId : encryptionUserIds) {
      OpenPgpUtils.UserId userId=KeyRing.splitUserId(rawUserId);
      String email=userId.email != null ? userId.email : rawUserId;
      Uri uri=KeyRings.buildUnifiedKeyRingsFindByEmailUri(email);
      Cursor cursor=getContentResolver().query(uri,KEY_SEARCH_PROJECTION,KEY_SEARCH_WHERE,null,null);
      try {
        if (cursor != null && cursor.moveToFirst()) {
          long id=cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID));
          keyIds.add(id);
        }
 else {
          missingEmails.add(email);
          Log.d(Constants.TAG,"String_Node_Str");
        }
        if (cursor != null && cursor.moveToNext()) {
          duplicateEmails.add(email);
          long id=cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID));
          keyIds.add(id);
          Log.d(Constants.TAG,"String_Node_Str");
        }
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
    }
  }
  boolean hasMissingUserIds=!missingEmails.isEmpty();
  boolean hasDuplicateUserIds=!duplicateEmails.isEmpty();
  if (isOpportunistic && (!hasUserIds || hasMissingUserIds)) {
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_ERROR,new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS,"String_Node_Str"));
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR);
    return new KeyIdResult(result);
  }
  if (!hasUserIds || hasMissingUserIds || hasDuplicateUserIds) {
    long[] keyIdsArray=getUnboxedLongArray(keyIds);
    ApiPendingIntentFactory piFactory=new ApiPendingIntentFactory(getBaseContext());
    PendingIntent pi=piFactory.createSelectPublicKeyPendingIntent(data,keyIdsArray,missingEmails,duplicateEmails,hasUserIds);
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_INTENT,pi);
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
    return new KeyIdResult(result);
  }
  if (keyIds.isEmpty()) {
    throw new AssertionError("String_Node_Str");
  }
  return new KeyIdResult(keyIds);
}