Program: 25802
Project: 25802
Buggy source:
private int backfillForStudy(Study study){
  int count=0;
  Application application=StormpathFactory.getStormpathApplication(stormpathClient);
  StormpathAccountIterator iterator=new StormpathAccountIterator(application);
  while (iterator.hasNext()) {
    List<Account> accountList=iterator.next();
    for (    Account account : accountList) {
      final CustomData customData=account.getCustomData();
      final String studyKey=study.getIdentifier();
      final String healthIdKey=studyKey + BridgeConstants.CUSTOM_DATA_HEALTH_CODE_SUFFIX;
      final Object healthIdObj=customData.get(healthIdKey);
      if (healthIdObj == null) {
        accountEncryptionService.createAndSaveHealthCode(study,account);
        count++;
        logger.info("String_Node_Str" + account.getEmail() + "String_Node_Str"+ study.getName());
      }
 else {
        int version=1;
        Object versionObj=customData.get(BridgeConstants.CUSTOM_DATA_VERSION);
        if (versionObj != null) {
          version=(Integer)versionObj;
        }
        if (version < 2) {
          String healthId=healthCodeEncryptorOld.decrypt((String)healthIdObj);
          String encryptedHealthId=healthCodeEncryptor.encrypt(healthId);
          customData.put(healthIdKey,encryptedHealthId);
          customData.put(BridgeConstants.CUSTOM_DATA_VERSION,2);
          customData.save();
          count++;
          logger.info("String_Node_Str" + account.getEmail() + "String_Node_Str"+ study.getName());
        }
      }
    }
  }
  return count;
}

Fixed version (ground truth):
private int backfillForStudy(Study study){
  int count=0;
  Application application=StormpathFactory.getStormpathApplication(stormpathClient);
  StormpathAccountIterator iterator=new StormpathAccountIterator(application);
  while (iterator.hasNext()) {
    List<Account> accountList=iterator.next();
    for (    Account account : accountList) {
      final CustomData customData=account.getCustomData();
      final String studyKey=study.getIdentifier();
      final String healthIdKey=studyKey + BridgeConstants.CUSTOM_DATA_HEALTH_CODE_SUFFIX;
      final Object healthIdObj=customData.get(healthIdKey);
      if (healthIdObj == null) {
        accountEncryptionService.createAndSaveHealthCode(study,account);
        count++;
        logger.info("String_Node_Str" + account.getEmail() + "String_Node_Str"+ study.getName());
      }
 else {
        int version=1;
        Object versionObj=customData.get(BridgeConstants.CUSTOM_DATA_VERSION);
        if (versionObj != null) {
          version=(Integer)versionObj;
        }
        if (version < 2) {
          String healthId=healthCodeEncryptorOld.decrypt((String)healthIdObj);
          String encryptedHealthId=healthCodeEncryptor.encrypt(healthId);
          customData.put(healthIdKey,encryptedHealthId);
          customData.put(BridgeConstants.CUSTOM_DATA_VERSION,2);
          customData.save();
          count++;
          logger.info("String_Node_Str" + account.getEmail() + "String_Node_Str"+ study.getName());
        }
        HealthId healthId=accountEncryptionService.getHealthCode(study,account);
        String healthCode=healthId.getCode();
        if (healthCode == null) {
          customData.remove(healthIdKey);
          accountEncryptionService.createAndSaveHealthCode(study,account);
          logger.info("String_Node_Str" + account.getEmail() + "String_Node_Str"+ study.getName());
        }
      }
    }
  }
  return count;
}