Program: 35409
Project: 35409
Buggy source:
/** 
 * Gets a flexible element value from the database.
 * @param cmd {@link GetValue} command containing the flexible element class, its id, and the project id
 * @return a {@link ValueResult} object containing the value of the flexible element or containing {@code null} ifthere is no value defined for this element.
 * @throws org.sigmah.shared.dispatch.CommandException
 */
@Override public ValueResult execute(final GetValue cmd,final UserExecutionContext context) throws CommandException {
  LOG.debug("String_Node_Str",cmd);
  final ValueResult valueResult=new ValueResult();
  String historyValue=null;
  if (cmd.getAmendmentId() != null) {
    final TypedQuery<Amendment> amedmentQuery=em().createQuery("String_Node_Str",Amendment.class);
    amedmentQuery.setParameter("String_Node_Str",cmd.getAmendmentId());
    final Amendment amendment=amedmentQuery.getSingleResult();
    final List<HistoryToken> tokens=amendment.getValues();
    if (tokens != null) {
      for (      final HistoryToken token : tokens) {
        if (token.getElementId().equals(cmd.getElementId()) && token.getLayoutGroupIterationId().equals(cmd.getIterationId())) {
          historyValue=token.getValue();
        }
      }
    }
  }
  final String valueFromDatabase;
  if (DefaultFlexibleElementDTO.ENTITY_NAME.equals(cmd.getElementEntityName())) {
    valueFromDatabase=findCurrentValueOfDefaultElement(cmd.getProjectId(),cmd.getElementId());
  }
 else   if (BudgetRatioElementDTO.ENTITY_NAME.equals(cmd.getElementEntityName())) {
    valueFromDatabase=findCurrentValueOfBudgetRatioElement(cmd.getProjectId(),cmd.getElementId());
  }
 else {
    valueFromDatabase=findCurrentValue(cmd.getProjectId(),cmd.getElementId(),cmd.getIterationId());
  }
  String valueAsString=valueFromDatabase;
  boolean isValueExisting=valueFromDatabase != null;
  if (historyValue != null) {
    valueAsString=historyValue;
    isValueExisting=true;
    valueResult.setAmendment(true);
  }
  if (!isValueExisting) {
    LOG.debug("String_Node_Str",cmd.getElementId());
    return valueResult;
  }
  Query query=null;
  String elementClassName=cmd.getElementEntityName();
  ListableValue dto=null;
  Boolean isList=null;
  if (elementClassName.equals(TripletsListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new TripletValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (elementClassName.equals(IndicatorsListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new IndicatorsListValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",Integer.valueOf(valueAsString));
  }
 else   if (elementClassName.equals(BudgetDistributionElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new BudgetPartsListValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",Integer.valueOf(valueAsString));
  }
 else   if (elementClassName.equals(FilesListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new FileDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (elementClassName.equals(ReportListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new ReportReference();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (!(elementClassName.equals(MessageElementDTO.ENTITY_NAME))) {
    LOG.debug("String_Node_Str");
    dto=null;
    isList=false;
  }
  if (isList == null) {
    return valueResult;
  }
  if (isList) {
    LOG.debug("String_Node_Str",cmd.getElementId());
    @SuppressWarnings("String_Node_Str") final List<Object> objectsList=query.getResultList();
    final List<ListableValue> serializablesList=new ArrayList<>();
    for (    Object o : objectsList) {
      serializablesList.add(mapper().map(o,dto));
    }
    if (elementClassName.equals(FilesListElementDTO.ENTITY_NAME)) {
      for (      final ListableValue value : serializablesList) {
        if (value instanceof FileDTO) {
          final FileDTO file=(FileDTO)value;
          for (          final FileVersionDTO version : file.getVersions()) {
            version.setAvailable(fileStorageProvider.exists(version.getPath()));
          }
        }
      }
    }
    valueResult.setValuesObject(serializablesList);
  }
 else {
    LOG.debug("String_Node_Str",cmd.getElementId());
    valueResult.setValueObject(valueAsString);
  }
  LOG.debug("String_Node_Str",valueResult);
  return valueResult;
}

Fixed version (ground truth):
/** 
 * Gets a flexible element value from the database.
 * @param cmd {@link GetValue} command containing the flexible element class, its id, and the project id
 * @return a {@link ValueResult} object containing the value of the flexible element or containing {@code null} ifthere is no value defined for this element.
 * @throws org.sigmah.shared.dispatch.CommandException
 */
@Override public ValueResult execute(final GetValue cmd,final UserExecutionContext context) throws CommandException {
  LOG.debug("String_Node_Str",cmd);
  final ValueResult valueResult=new ValueResult();
  String historyValue=null;
  if (cmd.getAmendmentId() != null) {
    final TypedQuery<Amendment> amedmentQuery=em().createQuery("String_Node_Str",Amendment.class);
    amedmentQuery.setParameter("String_Node_Str",cmd.getAmendmentId());
    final Amendment amendment=amedmentQuery.getSingleResult();
    final List<HistoryToken> tokens=amendment.getValues();
    if (tokens != null) {
      for (      final HistoryToken token : tokens) {
        if (token.getElementId().equals(cmd.getElementId()) && token.getLayoutGroupIterationId().equals(cmd.getIterationId())) {
          historyValue=token.getValue();
        }
      }
    }
  }
  final String valueFromDatabase;
  if (DefaultFlexibleElementDTO.ENTITY_NAME.equals(cmd.getElementEntityName())) {
    valueFromDatabase=findCurrentValueOfDefaultElement(cmd.getProjectId(),cmd.getElementId());
  }
 else   if (BudgetRatioElementDTO.ENTITY_NAME.equals(cmd.getElementEntityName())) {
    valueFromDatabase=findCurrentValueOfBudgetRatioElement(cmd.getProjectId(),cmd.getElementId());
  }
 else {
    valueFromDatabase=findCurrentValue(cmd.getProjectId(),cmd.getElementId(),cmd.getIterationId());
  }
  String valueAsString=valueFromDatabase;
  boolean isValueExisting=valueFromDatabase != null;
  if (historyValue != null) {
    valueAsString=historyValue;
    isValueExisting=true;
    valueResult.setAmendment(true);
  }
  if (!isValueExisting) {
    LOG.debug("String_Node_Str",cmd.getElementId());
    return valueResult;
  }
  Query query=null;
  String elementClassName=cmd.getElementEntityName();
  ListableValue dto=null;
  Boolean isList=null;
  if (elementClassName.equals(TripletsListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new TripletValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (elementClassName.equals(IndicatorsListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new IndicatorsListValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",Integer.valueOf(valueAsString));
  }
 else   if (elementClassName.equals(BudgetDistributionElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new BudgetPartsListValueDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",Integer.valueOf(valueAsString));
  }
 else   if (elementClassName.equals(FilesListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new FileDTO();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (elementClassName.equals(ReportListElementDTO.ENTITY_NAME)) {
    LOG.debug("String_Node_Str");
    dto=new ReportReference();
    isList=true;
    query=em().createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",ValueResultUtils.splitValuesAsInteger(valueAsString));
  }
 else   if (!(elementClassName.equals(MessageElementDTO.ENTITY_NAME))) {
    LOG.debug("String_Node_Str");
    dto=null;
    isList=false;
  }
  if (isList == null) {
    return valueResult;
  }
  if (isList) {
    LOG.debug("String_Node_Str",cmd.getElementId());
    @SuppressWarnings("String_Node_Str") final List<Object> objectsList=query.getResultList();
    final List<ListableValue> serializablesList=new ArrayList<>();
    for (    Object o : objectsList) {
      serializablesList.add(mapper().map(o,dto.getClass()));
    }
    if (elementClassName.equals(FilesListElementDTO.ENTITY_NAME)) {
      for (      final ListableValue value : serializablesList) {
        if (value instanceof FileDTO) {
          final FileDTO file=(FileDTO)value;
          for (          final FileVersionDTO version : file.getVersions()) {
            version.setAvailable(fileStorageProvider.exists(version.getPath()));
          }
        }
      }
    }
    valueResult.setValuesObject(serializablesList);
  }
 else {
    LOG.debug("String_Node_Str",cmd.getElementId());
    valueResult.setValueObject(valueAsString);
  }
  LOG.debug("String_Node_Str",valueResult);
  return valueResult;
}