Program: 188508
Project: 188508
Buggy source:
public static List<SupportedMetadataTypeBundle> retrieveSupportedMetadata(User user,IndexedAIP aip,IndexedRepresentation representation,Locale locale) throws GenericException {
  Messages messages=RodaCoreFactory.getI18NMessages(locale);
  List<String> types=RodaUtils.copyList(RodaCoreFactory.getRodaConfiguration().getList(RodaConstants.UI_BROWSER_METADATA_DESCRIPTIVE_TYPES));
  List<SupportedMetadataTypeBundle> supportedMetadata=new ArrayList<>();
  if (types != null) {
    for (    String id : types) {
      String type=id;
      String version=null;
      if (id.contains(RodaConstants.METADATA_VERSION_SEPARATOR)) {
        version=id.substring(id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR) + 1,id.length());
        type=id.substring(0,id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR));
      }
      String key=RodaConstants.I18N_UI_BROWSE_METADATA_DESCRIPTIVE_TYPE_PREFIX + type;
      if (version != null) {
        key+=RodaConstants.METADATA_VERSION_SEPARATOR + version;
      }
      String label=messages.getTranslation(key,type);
      InputStream templateStream=RodaCoreFactory.getConfigurationFileAsStream(RodaConstants.METADATA_TEMPLATE_FOLDER + "String_Node_Str" + ((version != null) ? type + RodaConstants.METADATA_VERSION_SEPARATOR + version : type)+ RodaConstants.METADATA_TEMPLATE_EXTENSION);
      String template=null;
      Set<MetadataValue> values=null;
      if (templateStream != null) {
        try {
          template=IOUtils.toString(templateStream,RodaConstants.DEFAULT_ENCODING);
          values=ServerTools.transform(template);
          for (          MetadataValue mv : values) {
            String generator=mv.get("String_Node_Str");
            if (generator != null && generator.length() > 0) {
              String value=null;
              if (representation != null) {
                value=ServerTools.autoGenerateRepresentationValue(representation,user,generator);
              }
 else {
                value=ServerTools.autoGenerateAIPValue(aip,user,generator);
              }
              if (value != null) {
                mv.set("String_Node_Str",value);
              }
            }
            String labels=mv.get("String_Node_Str");
            String labelI18N=mv.get("String_Node_Str");
            if (labels != null && labelI18N != null) {
              Map<String,String> labelsMaps=JsonUtils.getMapFromJson(labels);
              try {
                labelsMaps.put(locale.toString(),RodaCoreFactory.getI18NMessages(locale).getTranslation(labelI18N));
              }
 catch (              MissingResourceException e) {
                LOGGER.debug("String_Node_Str",labelI18N);
              }
              labels=JsonUtils.getJsonFromObject(labelsMaps);
              mv.set("String_Node_Str",labels);
            }
            String i18nPrefix=mv.get("String_Node_Str");
            if (i18nPrefix != null) {
              Map<String,String> terms=messages.getTranslations(i18nPrefix,String.class,false);
              if (terms.size() > 0) {
                try {
                  String options=mv.get("String_Node_Str");
                  List<String> optionsList=JsonUtils.getListFromJson(options,String.class);
                  if (optionsList != null) {
                    Map<String,Map<String,String>> i18nMap=new HashMap<String,Map<String,String>>();
                    for (int i=0; i < optionsList.size(); i++) {
                      String value=optionsList.get(i);
                      String translation=terms.get(i18nPrefix + "String_Node_Str" + value);
                      if (translation == null) {
                        translation=value;
                      }
                      Map<String,String> term=new HashMap<String,String>();
                      term.put(locale.toString(),translation);
                      i18nMap.put(value,term);
                    }
                    mv.set("String_Node_Str",JsonUtils.getJsonFromObject(i18nMap));
                  }
                }
 catch (                MissingResourceException e) {
                  LOGGER.error(e.getMessage(),e);
                }
              }
            }
          }
        }
 catch (        IOException e) {
          LOGGER.error("String_Node_Str",e);
        }
      }
      supportedMetadata.add(new SupportedMetadataTypeBundle(id,type,version,label,template,values));
    }
  }
  return supportedMetadata;
}

Fixed version (ground truth):
public static List<SupportedMetadataTypeBundle> retrieveSupportedMetadata(User user,IndexedAIP aip,IndexedRepresentation representation,Locale locale) throws GenericException {
  Messages messages=RodaCoreFactory.getI18NMessages(locale);
  List<String> types=RodaUtils.copyList(RodaCoreFactory.getRodaConfiguration().getList(RodaConstants.UI_BROWSER_METADATA_DESCRIPTIVE_TYPES));
  List<SupportedMetadataTypeBundle> supportedMetadata=new ArrayList<>();
  if (types != null) {
    for (    String id : types) {
      String type=id;
      String version=null;
      if (id.contains(RodaConstants.METADATA_VERSION_SEPARATOR)) {
        version=id.substring(id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR) + 1,id.length());
        type=id.substring(0,id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR));
      }
      String key=RodaConstants.I18N_UI_BROWSE_METADATA_DESCRIPTIVE_TYPE_PREFIX + type;
      if (version != null) {
        key+=RodaConstants.METADATA_VERSION_SEPARATOR + version.toLowerCase();
      }
      String label=messages.getTranslation(key,type);
      InputStream templateStream=RodaCoreFactory.getConfigurationFileAsStream(RodaConstants.METADATA_TEMPLATE_FOLDER + "String_Node_Str" + ((version != null) ? type + RodaConstants.METADATA_VERSION_SEPARATOR + version : type)+ RodaConstants.METADATA_TEMPLATE_EXTENSION);
      String template=null;
      Set<MetadataValue> values=null;
      if (templateStream != null) {
        try {
          template=IOUtils.toString(templateStream,RodaConstants.DEFAULT_ENCODING);
          values=ServerTools.transform(template);
          for (          MetadataValue mv : values) {
            String generator=mv.get("String_Node_Str");
            if (generator != null && generator.length() > 0) {
              String value=null;
              if (representation != null) {
                value=ServerTools.autoGenerateRepresentationValue(representation,user,generator);
              }
 else {
                value=ServerTools.autoGenerateAIPValue(aip,user,generator);
              }
              if (value != null) {
                mv.set("String_Node_Str",value);
              }
            }
            String labels=mv.get("String_Node_Str");
            String labelI18N=mv.get("String_Node_Str");
            if (labels != null && labelI18N != null) {
              Map<String,String> labelsMaps=JsonUtils.getMapFromJson(labels);
              try {
                labelsMaps.put(locale.toString(),RodaCoreFactory.getI18NMessages(locale).getTranslation(labelI18N));
              }
 catch (              MissingResourceException e) {
                LOGGER.debug("String_Node_Str",labelI18N);
              }
              labels=JsonUtils.getJsonFromObject(labelsMaps);
              mv.set("String_Node_Str",labels);
            }
            String i18nPrefix=mv.get("String_Node_Str");
            if (i18nPrefix != null) {
              Map<String,String> terms=messages.getTranslations(i18nPrefix,String.class,false);
              if (terms.size() > 0) {
                try {
                  String options=mv.get("String_Node_Str");
                  List<String> optionsList=JsonUtils.getListFromJson(options,String.class);
                  if (optionsList != null) {
                    Map<String,Map<String,String>> i18nMap=new HashMap<String,Map<String,String>>();
                    for (int i=0; i < optionsList.size(); i++) {
                      String value=optionsList.get(i);
                      String translation=terms.get(i18nPrefix + "String_Node_Str" + value);
                      if (translation == null) {
                        translation=value;
                      }
                      Map<String,String> term=new HashMap<String,String>();
                      term.put(locale.toString(),translation);
                      i18nMap.put(value,term);
                    }
                    mv.set("String_Node_Str",JsonUtils.getJsonFromObject(i18nMap));
                  }
                }
 catch (                MissingResourceException e) {
                  LOGGER.error(e.getMessage(),e);
                }
              }
            }
          }
        }
 catch (        IOException e) {
          LOGGER.error("String_Node_Str",e);
        }
      }
      supportedMetadata.add(new SupportedMetadataTypeBundle(id,type,version,label,template,values));
    }
  }
  return supportedMetadata;
}