Program: 35443
Project: 35443
Buggy source:
/** 
 * <p> Loads the given   {@code flexibleElement} <b>specific fields</b> and sets the corresponding form fields values.</p> <p> Executes  {@link #loadFlexibleElementTextAreaFields(FlexibleElementDTO,TextAreaType)} method if the{@code flexibleElement} is an instance of {@link TextAreaElementDTO}. </p>
 * @param flexibleElement The edited flexible element, may be  {@code null}.
 * @param type The element type, may be  {@code null}.
 */
private void loadFlexibleElementSpecificFields(final FlexibleElementDTO flexibleElement,final LogicalElementType type){
  view.getBudgetFields().setVisible(false);
  view.getAnchorAddSubField().setVisible(false);
  view.getRatioFlexTable().setVisible(false);
  view.clearBudgetFields();
  view.getUpBudgetSubFieldCombo().clearSelections();
  view.getDownBudgetSubFieldCombo().clearSelections();
  view.getUpBudgetSubFieldStore().removeAll();
  view.getUpBudgetSubFieldStore().commitChanges();
  view.getDownBudgetSubFieldStore().removeAll();
  view.getDownBudgetSubFieldStore().commitChanges();
  view.setSpecificFieldsVisibility(type);
  view.getBannerPositionField().disable();
  view.getBannerPositionField().setAllowBlank(true);
  customChoices.clear();
  disabledCustomChoices.clear();
  if (flexibleElement instanceof FilesListElementDTO) {
    view.getMaxLimitField().setValue(((FilesListElementDTO)flexibleElement).getLimit());
  }
 else   if (flexibleElement instanceof TextAreaElementDTO || type.toElementTypeEnum() == ElementTypeEnum.TEXT_AREA) {
    loadFlexibleElementTextAreaFields(flexibleElement,type.toTextAreaType());
  }
 else   if (flexibleElement instanceof QuestionElementDTO) {
    final QuestionElementDTO questionElement=(QuestionElementDTO)flexibleElement;
    view.setCustomChoiceAddFieldEnabled(true);
    view.getQualityLinkField().setValue(questionElement.getQualityCriterion() != null);
    view.getMultipleChoicesField().setValue(questionElement.getMultiple());
    view.getMultipleChoicesField().setEnabled(!isUpdateAndUnderMaintenance());
    if (ClientUtils.isNotEmpty(questionElement.getChoices())) {
      for (      final QuestionChoiceElementDTO choice : questionElement.getChoices()) {
        if (!isUpdateAndUnderMaintenance()) {
          onAddCustomChoice(choice.getLabel());
        }
 else {
          onAddUndeletableCustomChoice(choice.getLabel(),!choice.isDisabled());
        }
      }
    }
  }
 else   if (flexibleElement instanceof BudgetElementDTO) {
    final BudgetElementDTO budgetElement=(BudgetElementDTO)flexibleElement;
    view.getBudgetFields().setVisible(!isUpdateAndUnderMaintenance());
    view.getUpBudgetSubFieldCombo().setVisible(!isUpdateAndUnderMaintenance());
    view.getDownBudgetSubFieldCombo().setVisible(!isUpdateAndUnderMaintenance());
    int row=1;
    for (    final BudgetSubFieldDTO budgetField : budgetElement.getBudgetSubFields()) {
      final Text budgetText=new Text();
      budgetText.setData("String_Node_Str",budgetField);
      budgetText.addStyleName("String_Node_Str");
      if (budgetField.getType() != null) {
        budgetField.setLabel(BudgetSubFieldType.getName(budgetField.getType()));
      }
      budgetText.setText(budgetField.getLabel());
      view.getBudgetFields().setWidget(row,0,budgetText);
      view.getBudgetFields().setWidget(row,1,new TextField<String>());
      if (budgetField.getType() == null) {
        Anchor anchorEditSubField=new Anchor(IconImageBundle.ICONS.editPage().getSafeHtml());
        Anchor anchorDeleteSubField=new Anchor(IconImageBundle.ICONS.delete().getSafeHtml());
        view.getBudgetFields().setWidget(row,2,anchorEditSubField);
        view.getBudgetFields().setWidget(row,3,anchorDeleteSubField);
        anchorEditSubField.addClickHandler(new ClickHandler(){
          @Override public void onClick(          ClickEvent event){
            eventBus.navigateRequest(Page.ADMIN_EDIT_FLEXIBLE_ELEMENT_ADD_BUDGETSUBFIELD.request().addData(RequestParameter.DTO,budgetField));
          }
        }
);
        anchorDeleteSubField.addClickHandler(new ClickHandler(){
          @Override public void onClick(          ClickEvent event){
            budgetElement.getBudgetSubFields().remove(budgetField);
            loadFlexibleElement(flexibleElement);
          }
        }
);
      }
      budgetText.show();
      if (budgetField.getId() != null) {
        view.getUpBudgetSubFieldStore().add(budgetField);
        view.getDownBudgetSubFieldStore().add(budgetField);
      }
      row++;
    }
    view.getUpBudgetSubFieldStore().commitChanges();
    view.getDownBudgetSubFieldStore().commitChanges();
    for (    BudgetSubFieldDTO budgetField : budgetElement.getBudgetSubFields()) {
      if (budgetField.getId() != null) {
        if (budgetField.getId().equals(budgetElement.getRatioDividend().getId())) {
          view.getUpBudgetSubFieldCombo().setValue(budgetField);
        }
        if (budgetField.getId().equals(budgetElement.getRatioDivisor().getId())) {
          view.getDownBudgetSubFieldCombo().setValue(budgetField);
        }
      }
    }
    view.getSpecificForm().recalculate();
  }
 else   if (flexibleElement instanceof ComputationElementDTO) {
    final ComputationElementDTO computationElement=(ComputationElementDTO)flexibleElement;
    final String formattedRule=Computations.formatRuleForEdition(computationElement.getRule(),otherElements);
    view.getFormulaField().setValue(formattedRule);
    view.getMinLimitField().setValue(ComputedValues.from(computationElement.getMinimumValue(),false).get());
    view.getMaxLimitField().setValue(ComputedValues.from(computationElement.getMaximumValue(),false).get());
  }
  if (type == ElementTypeEnum.COMPUTATION) {
    addNumberTypeToStore(view.getStore());
  }
  if (type == DefaultFlexibleElementType.BUDGET_RATIO) {
    addNumberTypeToStore(view.getBudgetSubFieldSpentStore(),view.getBudgetSubFieldPlannedStore());
  }
  if (flexibleElement instanceof BudgetRatioElementDTO) {
    final BudgetRatioElementDTO budgetRatioElementDTO=(BudgetRatioElementDTO)flexibleElement;
    if (budgetRatioElementDTO.getSpentBudget() != null) {
      view.getBudgetSubFieldSpentCombo().setSelection(java.util.Collections.singletonList(budgetRatioElementDTO.getSpentBudget()));
    }
    if (budgetRatioElementDTO.getPlannedBudget() != null) {
      view.getBudgetSubFieldPlannedCombo().setSelection(java.util.Collections.singletonList(budgetRatioElementDTO.getPlannedBudget()));
    }
  }
}

Fixed version (ground truth):
/** 
 * <p> Loads the given   {@code flexibleElement} <b>specific fields</b> and sets the corresponding form fields values.</p> <p> Executes  {@link #loadFlexibleElementTextAreaFields(FlexibleElementDTO,TextAreaType)} method if the{@code flexibleElement} is an instance of {@link TextAreaElementDTO}. </p>
 * @param flexibleElement The edited flexible element, may be  {@code null}.
 * @param type The element type, may be  {@code null}.
 */
private void loadFlexibleElementSpecificFields(final FlexibleElementDTO flexibleElement,final LogicalElementType type){
  view.getBudgetFields().setVisible(false);
  view.getAnchorAddSubField().setVisible(false);
  view.getRatioFlexTable().setVisible(false);
  view.clearBudgetFields();
  view.getUpBudgetSubFieldCombo().clearSelections();
  view.getDownBudgetSubFieldCombo().clearSelections();
  view.getUpBudgetSubFieldStore().removeAll();
  view.getUpBudgetSubFieldStore().commitChanges();
  view.getDownBudgetSubFieldStore().removeAll();
  view.getDownBudgetSubFieldStore().commitChanges();
  view.setSpecificFieldsVisibility(type);
  view.getBannerPositionField().disable();
  view.getBannerPositionField().setAllowBlank(true);
  customChoices.clear();
  disabledCustomChoices.clear();
  if (flexibleElement instanceof FilesListElementDTO) {
    view.getMaxLimitField().setValue(((FilesListElementDTO)flexibleElement).getLimit());
  }
 else   if (flexibleElement instanceof TextAreaElementDTO || type.toElementTypeEnum() == ElementTypeEnum.TEXT_AREA) {
    loadFlexibleElementTextAreaFields(flexibleElement,type.toTextAreaType());
  }
 else   if (flexibleElement instanceof QuestionElementDTO) {
    final QuestionElementDTO questionElement=(QuestionElementDTO)flexibleElement;
    view.setCustomChoiceAddFieldEnabled(true);
    view.getQualityLinkField().setValue(questionElement.getQualityCriterion() != null);
    view.getMultipleChoicesField().setValue(questionElement.getMultiple());
    view.getMultipleChoicesField().setEnabled(!isUpdateAndUnderMaintenance());
    if (ClientUtils.isNotEmpty(questionElement.getChoices())) {
      for (      final QuestionChoiceElementDTO choice : questionElement.getChoices()) {
        if (!isUpdateAndUnderMaintenance()) {
          onAddCustomChoice(choice.getLabel());
        }
 else {
          onAddUndeletableCustomChoice(choice.getLabel(),!choice.isDisabled());
        }
      }
    }
  }
 else   if (flexibleElement instanceof BudgetElementDTO) {
    final BudgetElementDTO budgetElement=(BudgetElementDTO)flexibleElement;
    view.getBudgetFields().setVisible(!isUpdateAndUnderMaintenance());
    view.getUpBudgetSubFieldCombo().setVisible(!isUpdateAndUnderMaintenance());
    view.getDownBudgetSubFieldCombo().setVisible(!isUpdateAndUnderMaintenance());
    int row=1;
    for (    final BudgetSubFieldDTO budgetField : budgetElement.getBudgetSubFields()) {
      final Text budgetText=new Text();
      budgetText.setData("String_Node_Str",budgetField);
      budgetText.addStyleName("String_Node_Str");
      if (budgetField.getType() != null) {
        budgetField.setLabel(BudgetSubFieldType.getName(budgetField.getType()));
      }
      budgetText.setText(budgetField.getLabel());
      view.getBudgetFields().setWidget(row,0,budgetText);
      view.getBudgetFields().setWidget(row,1,new TextField<String>());
      if (budgetField.getType() == null) {
        Anchor anchorEditSubField=new Anchor(IconImageBundle.ICONS.editPage().getSafeHtml());
        Anchor anchorDeleteSubField=new Anchor(IconImageBundle.ICONS.delete().getSafeHtml());
        view.getBudgetFields().setWidget(row,2,anchorEditSubField);
        view.getBudgetFields().setWidget(row,3,anchorDeleteSubField);
        anchorEditSubField.addClickHandler(new ClickHandler(){
          @Override public void onClick(          ClickEvent event){
            eventBus.navigateRequest(Page.ADMIN_EDIT_FLEXIBLE_ELEMENT_ADD_BUDGETSUBFIELD.request().addData(RequestParameter.DTO,budgetField));
          }
        }
);
        anchorDeleteSubField.addClickHandler(new ClickHandler(){
          @Override public void onClick(          ClickEvent event){
            budgetElement.getBudgetSubFields().remove(budgetField);
            loadFlexibleElement(flexibleElement);
          }
        }
);
      }
      budgetText.show();
      if (budgetField.getId() != null) {
        view.getUpBudgetSubFieldStore().add(budgetField);
        view.getDownBudgetSubFieldStore().add(budgetField);
      }
      row++;
    }
    view.getUpBudgetSubFieldStore().commitChanges();
    view.getDownBudgetSubFieldStore().commitChanges();
    for (    BudgetSubFieldDTO budgetField : budgetElement.getBudgetSubFields()) {
      if (budgetField.getId() != null) {
        if (budgetField.getId().equals(budgetElement.getRatioDividend().getId())) {
          view.getUpBudgetSubFieldCombo().setValue(budgetField);
        }
        if (budgetField.getId().equals(budgetElement.getRatioDivisor().getId())) {
          view.getDownBudgetSubFieldCombo().setValue(budgetField);
        }
      }
    }
    view.getSpecificForm().recalculate();
  }
 else   if (flexibleElement instanceof ComputationElementDTO) {
    final ComputationElementDTO computationElement=(ComputationElementDTO)flexibleElement;
    final String formattedRule=Computations.formatRuleForEdition(computationElement.getRule(),otherElements);
    view.getFormulaField().setValue(formattedRule);
    view.getMinLimitField().setValue(ComputedValues.from(computationElement.getMinimumValue(),false).get());
    view.getMaxLimitField().setValue(ComputedValues.from(computationElement.getMaximumValue(),false).get());
  }
  if (type == ElementTypeEnum.COMPUTATION) {
    addNumberTypeToStore(view.getStore());
  }
 else   if (type == ElementTypeEnum.CONTACT_LIST) {
    loadContactListOptions((ContactListElementDTO)flexibleElement);
  }
  if (type == DefaultFlexibleElementType.BUDGET_RATIO) {
    addNumberTypeToStore(view.getBudgetSubFieldSpentStore(),view.getBudgetSubFieldPlannedStore());
  }
  if (flexibleElement instanceof BudgetRatioElementDTO) {
    final BudgetRatioElementDTO budgetRatioElementDTO=(BudgetRatioElementDTO)flexibleElement;
    if (budgetRatioElementDTO.getSpentBudget() != null) {
      view.getBudgetSubFieldSpentCombo().setSelection(java.util.Collections.singletonList(budgetRatioElementDTO.getSpentBudget()));
    }
    if (budgetRatioElementDTO.getPlannedBudget() != null) {
      view.getBudgetSubFieldPlannedCombo().setSelection(java.util.Collections.singletonList(budgetRatioElementDTO.getPlannedBudget()));
    }
  }
}