Program: 35671
Project: 35671
Buggy source:
private void createFlexibleElement(final AsyncCallback<UpdateModelResult> callback){
  if (!commonPanel.isValid() || htmlArea.getValue() != null && htmlArea.getValue().isEmpty() || "String_Node_Str".equals(htmlArea.getValue())) {
    MessageBox.alert(I18N.CONSTANTS.createFormIncomplete(),I18N.MESSAGES.createFormIncompleteDetails(I18N.CONSTANTS.adminStandardFlexibleName()),null);
    return;
  }
  final String name=htmlArea.getValue().replace("String_Node_Str","String_Node_Str");
  String type=null;
  if (typeList.getSimpleValue() != null)   type=typeList.getSimpleValue();
  LayoutGroupDTO group=groupList.getValue();
  Integer order=null;
  if (orderField.getValue() != null)   order=new Integer(orderField.getValue().intValue());
  Boolean inBanner=isBanner.getValue();
  Integer posB=null;
  if (posBanner.getValue() != null)   posB=posBanner.getValue().getValue();
  Boolean isCompulsory=validates.getValue();
  PrivacyGroupDTO pg=privacyGroupsListCombo.getValue();
  Boolean amend=isAmendable.getValue();
  String textType=null;
  if (textAreaTypeList.getValue() != null)   textType=textAreaTypeList.getSimpleValue();
  Character textTypeC=null;
  if (I18N.CONSTANTS.adminFlexibleTextTypeP().equals(textType)) {
    textTypeC='P';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeT().equals(textType)) {
    textTypeC='T';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeN().equals(textType)) {
    textTypeC='N';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeD().equals(textType)) {
    textTypeC='D';
  }
  Integer maxLimit=null;
  if (maxLimitField.getValue() != null)   maxLimit=new Integer(maxLimitField.getValue().intValue());
  Integer minLimit=null;
  if (minLimitField.getValue() != null)   minLimit=new Integer(minLimitField.getValue().intValue());
  Integer length=null;
  if (lengthField.getValue() != null)   length=new Integer(lengthField.getValue().intValue());
  Boolean decimal=isDecimal.getValue();
  ReportModelDTO reportModel=reportModelList.getValue();
  Boolean multipleQ=isMultipleQ.getValue();
  CategoryTypeDTO category=linkedCategory.getValue();
  HashMap<String,Object> newFieldProperties=new HashMap<String,Object>();
  newFieldProperties.put(AdminUtil.PROP_FX_NAME,name);
  newFieldProperties.put(AdminUtil.PROP_FX_TYPE,ElementTypeEnum.getType(type));
  newFieldProperties.put(AdminUtil.PROP_FX_GROUP,group);
  newFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,order);
  newFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,inBanner);
  newFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,posB);
  newFieldProperties.put(AdminUtil.PROP_FX_IS_COMPULSARY,isCompulsory);
  newFieldProperties.put(AdminUtil.PROP_FX_PRIVACY_GROUP,pg);
  newFieldProperties.put(AdminUtil.PROP_FX_AMENDABLE,amend);
  if (textTypeC != null)   newFieldProperties.put(AdminUtil.PROP_FX_TEXT_TYPE,textTypeC);
  if (length != null)   newFieldProperties.put(AdminUtil.PROP_FX_LENGTH,length);
  if (maxLimit != null)   newFieldProperties.put(AdminUtil.PROP_FX_MAX_LIMIT,maxLimit);
  if (minLimit != null)   newFieldProperties.put(AdminUtil.PROP_FX_MIN_LIMIT,minLimit);
  if (decimal != null && ElementTypeEnum.TEXT_AREA.equals(ElementTypeEnum.getType(type)))   newFieldProperties.put(AdminUtil.PROP_FX_DECIMAL,decimal);
  if (reportModel != null)   newFieldProperties.put(AdminUtil.PROP_FX_REPORT_MODEL,reportModel);
  if (multipleQ != null)   newFieldProperties.put(AdminUtil.PROP_FX_Q_MULTIPLE,multipleQ);
  if (category != null && category != defaultNoCategory)   newFieldProperties.put(AdminUtil.PROP_FX_Q_CATEGORY,category);
  if (selectedChoicesLabels != null)   newFieldProperties.put(AdminUtil.PROP_FX_Q_CHOICES,selectedChoicesLabels);
  for (  String selLab : selectedChoicesLabels) {
    Log.debug("String_Node_Str" + selLab);
  }
  String message="String_Node_Str";
  for (  Map.Entry<String,Object> newP : newFieldProperties.entrySet()) {
    message+=newP.getKey() + "String_Node_Str" + newP.getValue()+ "String_Node_Str";
  }
  Log.debug(message + "String_Node_Str");
  if (flexibleElementToUpdate != null) {
    message="String_Node_Str";
    for (    Map.Entry<String,Object> old : oldFieldProperties.entrySet()) {
      message+=old.getKey() + "String_Node_Str" + old.getValue()+ "String_Node_Str";
      if ((old.getValue() != null && old.getValue().equals(newFieldProperties.get(old.getKey()))) || (old.getValue() == null && newFieldProperties.get(old.getKey()) == null)) {
        newFieldProperties.remove(old.getKey());
      }
    }
    Log.debug(message + "String_Node_Str");
  }
  message="String_Node_Str";
  for (  Map.Entry<String,Object> newP : newFieldProperties.entrySet()) {
    if (newP.getValue() != null)     message+=newP.getKey() + "String_Node_Str" + newP.getValue()+ "String_Node_Str";
  }
  Log.debug(message + "String_Node_Str");
  if (newFieldProperties.get(AdminUtil.PROP_FX_ORDER_IN_GROUP) != null) {
    newFieldProperties.put(AdminUtil.PROP_FX_GROUP,group);
  }
  if (flexibleElementToUpdate != null)   newFieldProperties.put(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT,flexibleElementToUpdate);
 else   newFieldProperties.put(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT,new TextAreaElementDTO());
  newFieldProperties.put(AdminUtil.ADMIN_PROJECT_MODEL,projectModelToUpdate);
  newFieldProperties.put(AdminUtil.ADMIN_ORG_UNIT_MODEL,orgUnitModelToUpdate);
  newFieldProperties.put(AdminUtil.PROP_FX_OLD_FIELDS,oldFieldProperties);
  if (isProject) {
    dispatcher.execute(new CreateEntity("String_Node_Str",newFieldProperties),null,new AsyncCallback<CreateResult>(){
      public void onFailure(      Throwable caught){
        MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationFailure(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
        callback.onFailure(caught);
      }
      @Override public void onSuccess(      CreateResult result){
        if (result != null) {
          ProjectModelDTO pModelUpdated=(ProjectModelDTO)result.getEntity();
          UpdateModelResult completeResult=new UpdateModelResult(pModelUpdated.getId());
          completeResult.setEntity(pModelUpdated);
          if (flexibleElementToUpdate != null) {
            for (            FlexibleElementDTO f : pModelUpdated.getAllElements()) {
              if (f.getId() == flexibleElementToUpdate.getId()) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardUpdateSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
 else {
            List<Integer> flexibleIds=new ArrayList<Integer>();
            for (            FlexibleElementDTO f : projectModelToUpdate.getAllElements()) {
              flexibleIds.add(f.getId());
            }
            for (            FlexibleElementDTO f : pModelUpdated.getAllElements()) {
              if (!flexibleIds.contains(f.getId())) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
          callback.onSuccess(completeResult);
        }
 else {
          Throwable t=new Throwable("String_Node_Str");
          MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationNull(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
          callback.onFailure(t);
        }
      }
    }
);
  }
 else {
    dispatcher.execute(new CreateEntity("String_Node_Str",newFieldProperties),null,new AsyncCallback<CreateResult>(){
      public void onFailure(      Throwable caught){
        MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationFailure(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
        callback.onFailure(caught);
      }
      @Override public void onSuccess(      CreateResult result){
        if (result != null) {
          OrgUnitModelDTO oModelUpdated=(OrgUnitModelDTO)result.getEntity();
          UpdateModelResult completeResult=new UpdateModelResult(oModelUpdated.getId());
          completeResult.setEntity(oModelUpdated);
          if (flexibleElementToUpdate != null) {
            for (            FlexibleElementDTO f : oModelUpdated.getAllElements()) {
              if (f.getId() == flexibleElementToUpdate.getId()) {
                Log.debug("String_Node_Str" + f.getId());
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardUpdateSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
 else {
            List<Integer> flexibleIds=new ArrayList<Integer>();
            for (            FlexibleElementDTO f : orgUnitModelToUpdate.getAllElements()) {
              flexibleIds.add(f.getId());
            }
            for (            FlexibleElementDTO f : oModelUpdated.getAllElements()) {
              if (!flexibleIds.contains(f.getId())) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
          callback.onSuccess(completeResult);
        }
 else {
          Throwable t=new Throwable("String_Node_Str");
          MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationNull(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
          callback.onFailure(t);
        }
      }
    }
);
  }
}

Fixed version (ground truth):
private void createFlexibleElement(final AsyncCallback<UpdateModelResult> callback){
  if (!commonPanel.isValid() || htmlArea.getValue() != null && htmlArea.getValue().isEmpty() || "String_Node_Str".equals(htmlArea.getValue())) {
    MessageBox.alert(I18N.CONSTANTS.createFormIncomplete(),I18N.MESSAGES.createFormIncompleteDetails(I18N.CONSTANTS.adminStandardFlexibleName()),null);
    return;
  }
  final String name=htmlArea.getValue().replace("String_Node_Str","String_Node_Str");
  String type=null;
  if (typeList.getSimpleValue() != null)   type=typeList.getSimpleValue();
  LayoutGroupDTO group=groupList.getValue();
  Integer order=null;
  if (orderField.getValue() != null)   order=new Integer(orderField.getValue().intValue());
  Boolean isCompulsory=validates.getValue();
  PrivacyGroupDTO pg=privacyGroupsListCombo.getValue();
  Boolean amend=isAmendable.getValue();
  Boolean inBanner=isBanner.getValue();
  Integer posB=null;
  if (posBanner.getValue() != null)   posB=posBanner.getValue().getValue();
  String textType=null;
  if (textAreaTypeList.getValue() != null)   textType=textAreaTypeList.getSimpleValue();
  Character textTypeC=null;
  if (I18N.CONSTANTS.adminFlexibleTextTypeP().equals(textType)) {
    textTypeC='P';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeT().equals(textType)) {
    textTypeC='T';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeN().equals(textType)) {
    textTypeC='N';
  }
 else   if (I18N.CONSTANTS.adminFlexibleTextTypeD().equals(textType)) {
    textTypeC='D';
  }
  Integer maxLimit=null;
  if (maxLimitField.getValue() != null)   maxLimit=new Integer(maxLimitField.getValue().intValue());
  Integer minLimit=null;
  if (minLimitField.getValue() != null)   minLimit=new Integer(minLimitField.getValue().intValue());
  Integer length=null;
  if (lengthField.getValue() != null)   length=new Integer(lengthField.getValue().intValue());
  Boolean decimal=isDecimal.getValue();
  ReportModelDTO reportModel=reportModelList.getValue();
  Boolean multipleQ=isMultipleQ.getValue();
  CategoryTypeDTO category=linkedCategory.getValue();
  HashMap<String,Object> newFieldProperties=new HashMap<String,Object>();
  newFieldProperties.put(AdminUtil.PROP_FX_NAME,name);
  newFieldProperties.put(AdminUtil.PROP_FX_TYPE,ElementTypeEnum.getType(type));
  newFieldProperties.put(AdminUtil.PROP_FX_GROUP,group);
  newFieldProperties.put(AdminUtil.PROP_FX_ORDER_IN_GROUP,order);
  newFieldProperties.put(AdminUtil.PROP_FX_IN_BANNER,inBanner);
  newFieldProperties.put(AdminUtil.PROP_FX_POS_IN_BANNER,posB);
  newFieldProperties.put(AdminUtil.PROP_FX_IS_COMPULSARY,isCompulsory);
  newFieldProperties.put(AdminUtil.PROP_FX_PRIVACY_GROUP,pg);
  newFieldProperties.put(AdminUtil.PROP_FX_AMENDABLE,amend);
  if (textTypeC != null)   newFieldProperties.put(AdminUtil.PROP_FX_TEXT_TYPE,textTypeC);
  if (length != null)   newFieldProperties.put(AdminUtil.PROP_FX_LENGTH,length);
  if (maxLimit != null)   newFieldProperties.put(AdminUtil.PROP_FX_MAX_LIMIT,maxLimit);
  if (minLimit != null)   newFieldProperties.put(AdminUtil.PROP_FX_MIN_LIMIT,minLimit);
  if (decimal != null && ElementTypeEnum.TEXT_AREA.equals(ElementTypeEnum.getType(type)))   newFieldProperties.put(AdminUtil.PROP_FX_DECIMAL,decimal);
  if (reportModel != null)   newFieldProperties.put(AdminUtil.PROP_FX_REPORT_MODEL,reportModel);
  if (multipleQ != null)   newFieldProperties.put(AdminUtil.PROP_FX_Q_MULTIPLE,multipleQ);
  if (category != null && category != defaultNoCategory)   newFieldProperties.put(AdminUtil.PROP_FX_Q_CATEGORY,category);
  if (selectedChoicesLabels != null)   newFieldProperties.put(AdminUtil.PROP_FX_Q_CHOICES,selectedChoicesLabels);
  for (  String selLab : selectedChoicesLabels) {
    Log.debug("String_Node_Str" + selLab);
  }
  String message="String_Node_Str";
  for (  Map.Entry<String,Object> newP : newFieldProperties.entrySet()) {
    message+=newP.getKey() + "String_Node_Str" + newP.getValue()+ "String_Node_Str";
  }
  Log.debug(message + "String_Node_Str");
  if (flexibleElementToUpdate != null) {
    message="String_Node_Str";
    for (    Map.Entry<String,Object> old : oldFieldProperties.entrySet()) {
      message+=old.getKey() + "String_Node_Str" + old.getValue()+ "String_Node_Str";
      if ((old.getValue() != null && old.getValue().equals(newFieldProperties.get(old.getKey()))) || (old.getValue() == null && newFieldProperties.get(old.getKey()) == null)) {
        newFieldProperties.remove(old.getKey());
      }
    }
    Log.debug(message + "String_Node_Str");
  }
  message="String_Node_Str";
  for (  Map.Entry<String,Object> newP : newFieldProperties.entrySet()) {
    if (newP.getValue() != null)     message+=newP.getKey() + "String_Node_Str" + newP.getValue()+ "String_Node_Str";
  }
  Log.debug(message + "String_Node_Str");
  if (newFieldProperties.get(AdminUtil.PROP_FX_ORDER_IN_GROUP) != null) {
    newFieldProperties.put(AdminUtil.PROP_FX_GROUP,group);
  }
  if (flexibleElementToUpdate != null)   newFieldProperties.put(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT,flexibleElementToUpdate);
 else   newFieldProperties.put(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT,new TextAreaElementDTO());
  newFieldProperties.put(AdminUtil.ADMIN_PROJECT_MODEL,projectModelToUpdate);
  newFieldProperties.put(AdminUtil.ADMIN_ORG_UNIT_MODEL,orgUnitModelToUpdate);
  newFieldProperties.put(AdminUtil.PROP_FX_OLD_FIELDS,oldFieldProperties);
  if (isProject) {
    dispatcher.execute(new CreateEntity("String_Node_Str",newFieldProperties),null,new AsyncCallback<CreateResult>(){
      public void onFailure(      Throwable caught){
        MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationFailure(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
        callback.onFailure(caught);
      }
      @Override public void onSuccess(      CreateResult result){
        if (result != null) {
          ProjectModelDTO pModelUpdated=(ProjectModelDTO)result.getEntity();
          UpdateModelResult completeResult=new UpdateModelResult(pModelUpdated.getId());
          completeResult.setEntity(pModelUpdated);
          if (flexibleElementToUpdate != null) {
            for (            FlexibleElementDTO f : pModelUpdated.getAllElements()) {
              if (f.getId() == flexibleElementToUpdate.getId()) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardUpdateSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
 else {
            List<Integer> flexibleIds=new ArrayList<Integer>();
            for (            FlexibleElementDTO f : projectModelToUpdate.getAllElements()) {
              flexibleIds.add(f.getId());
            }
            for (            FlexibleElementDTO f : pModelUpdated.getAllElements()) {
              if (!flexibleIds.contains(f.getId())) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
          callback.onSuccess(completeResult);
        }
 else {
          Throwable t=new Throwable("String_Node_Str");
          MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationNull(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
          callback.onFailure(t);
        }
      }
    }
);
  }
 else {
    dispatcher.execute(new CreateEntity("String_Node_Str",newFieldProperties),null,new AsyncCallback<CreateResult>(){
      public void onFailure(      Throwable caught){
        MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationFailure(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
        callback.onFailure(caught);
      }
      @Override public void onSuccess(      CreateResult result){
        if (result != null) {
          OrgUnitModelDTO oModelUpdated=(OrgUnitModelDTO)result.getEntity();
          UpdateModelResult completeResult=new UpdateModelResult(oModelUpdated.getId());
          completeResult.setEntity(oModelUpdated);
          if (flexibleElementToUpdate != null) {
            for (            FlexibleElementDTO f : oModelUpdated.getAllElements()) {
              if (f.getId() == flexibleElementToUpdate.getId()) {
                Log.debug("String_Node_Str" + f.getId());
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardUpdateSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
 else {
            List<Integer> flexibleIds=new ArrayList<Integer>();
            for (            FlexibleElementDTO f : orgUnitModelToUpdate.getAllElements()) {
              flexibleIds.add(f.getId());
            }
            for (            FlexibleElementDTO f : oModelUpdated.getAllElements()) {
              if (!flexibleIds.contains(f.getId())) {
                completeResult.setAnnexEntity(f);
              }
            }
            Notification.show(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationSuccess(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"));
          }
          callback.onSuccess(completeResult);
        }
 else {
          Throwable t=new Throwable("String_Node_Str");
          MessageBox.alert(I18N.CONSTANTS.adminFlexibleCreationBox(),I18N.MESSAGES.adminStandardCreationNull(I18N.CONSTANTS.adminStandardFlexibleName() + "String_Node_Str" + name+ "String_Node_Str"),null);
          callback.onFailure(t);
        }
      }
    }
);
  }
}