Program: 35679
Project: 35679
Buggy source:
public ProfileSigmahForm(Dispatcher dispatcher,UserLocalCache userCache,final AsyncCallback<CreateResult> callback,ProfileDTO profileToUpdate){
  this.dispatcher=dispatcher;
  this.profileToUpdate=profileToUpdate;
  UIConstants constants=GWT.create(UIConstants.class);
  FormLayout layout=new FormLayout();
  layout.setLabelWidth(LABEL_WIDTH);
  setLayout(layout);
  nameField=new TextField<String>();
  nameField.setFieldLabel(constants.adminProfilesName());
  nameField.setAllowBlank(false);
  if (profileToUpdate != null && !profileToUpdate.getName().isEmpty())   nameField.setValue(profileToUpdate.getName());
  add(nameField);
  checkGlobalPermissions=new ArrayList<CheckBoxGroup>();
  CheckBoxGroup checkGPGroup=new CheckBoxGroup();
  checkGPGroup.setOrientation(Orientation.VERTICAL);
  checkGPGroup.setFieldLabel(I18N.CONSTANTS.adminProfilesGlobalPermissions());
  String label="String_Node_Str";
  for (  GlobalPermissionEnum enumItem : GlobalPermissionEnum.values()) {
    label=GlobalPermissionEnum.getName(enumItem);
    CheckBox box=createCheckBox(enumItem.toString(),label);
    if (profileToUpdate != null && profileToUpdate.getGlobalPermissions() != null && profileToUpdate.getGlobalPermissions().contains(enumItem)) {
      box.setValue(true);
    }
    checkGPGroup.add(box);
  }
  checkGlobalPermissions.add(checkGPGroup);
  add(checkGPGroup);
  for (int i1=0; i1 < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER; i1++) {
    final ClickableLabel pglabel=new ClickableLabel();
    pglabel.hide();
    pglabel.addClickHandler(new ClickHandler(){
      @Override public void onClick(      ClickEvent arg0){
        pglabel.removeFromParent();
        selectedPrivacyGroupsIds.remove(new Integer(((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP)).getId()));
        if (privacyGroupsPerms.containsKey((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP))) {
        }
        privacyGroupsPerms.remove((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP));
      }
    }
);
    selectedPrivacyGroups.put(i1,pglabel);
  }
  privacyGroupsPermissionsListCombo=new ComboBox<PrivacyGroupPermDTO>();
  privacyGroupsPermissionsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsPermissionsListCombo.setValueField("String_Node_Str");
  privacyGroupsPermissionsListCombo.setEditable(false);
  privacyGroupsPermissionsListCombo.setTriggerAction(TriggerAction.ALL);
  int j=0;
  ListStore<PrivacyGroupPermDTO> permsStore=new ListStore<PrivacyGroupPermDTO>();
  for (  PrivacyGroupPermissionEnum enumItem : PrivacyGroupPermissionEnum.values()) {
    j++;
    PrivacyGroupPermDTO perm=new PrivacyGroupPermDTO();
    perm.setId(j);
    perm.setPermission(PrivacyGroupPermissionEnum.getName(enumItem));
    permsStore.add(perm);
  }
  privacyGroupsPermissionsListCombo.setStore(permsStore);
  privacyGroupsListCombo=new ComboBox<PrivacyGroupDTO>();
  privacyGroupsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsListCombo.setValueField("String_Node_Str");
  privacyGroupsListCombo.setEditable(false);
  privacyGroupsListCombo.setTriggerAction(TriggerAction.ALL);
  final ListStore<PrivacyGroupDTO> privacyGroupsStore=new ListStore<PrivacyGroupDTO>();
  dispatcher.execute(new GetPrivacyGroups(),null,new AsyncCallback<PrivacyGroupsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    PrivacyGroupsListResult result){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminPrivacyGroupChoice());
      privacyGroupsStore.removeAll();
      if (result != null) {
        privacyGroupsStore.add(result.getList());
        privacyGroupsStore.commitChanges();
      }
    }
  }
);
  privacyGroupsListCombo.setStore(privacyGroupsStore);
  final Grid privacyGroupsAddSelectionGrid=new Grid(1,4);
  privacyGroupsAddSelectionGrid.getCellFormatter().setWidth(0,0,(LABEL_WIDTH + 5) + "String_Node_Str");
  privacyGroupsAddSelectionGrid.setCellPadding(0);
  privacyGroupsAddSelectionGrid.setCellSpacing(0);
  privacyGroupsAddSelectionGrid.setWidget(0,0,new LabelField(I18N.CONSTANTS.adminProfilesPrivacyGroups() + "String_Node_Str"));
  privacyGroupsAddSelectionGrid.setWidget(0,1,privacyGroupsListCombo);
  privacyGroupsAddSelectionGrid.setWidget(0,2,privacyGroupsPermissionsListCombo);
  privacyGroupsListCombo.setHideLabel(false);
  if (profileToUpdate != null && profileToUpdate.getPrivacyGroups() != null) {
    Set<PrivacyGroupDTO> usedPrivacyGroups=profileToUpdate.getPrivacyGroups().keySet();
    for (    PrivacyGroupDTO usedPrivacyGroup : usedPrivacyGroups) {
      selectedPrivacyGroupsIds.add(new Integer(usedPrivacyGroup.getId()));
      privacyGroupsPerms.put(usedPrivacyGroup,profileToUpdate.getPrivacyGroups().get(usedPrivacyGroup));
    }
  }
  final Button addButton=new Button(I18N.CONSTANTS.addItem());
  addButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      if (privacyGroupsListCombo.getValue() != null) {
        if (!selectedPrivacyGroupsIds.contains(new Integer(privacyGroupsListCombo.getValue().getId()))) {
          if (num < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER) {
            selectedPrivacyGroups.get(num).setData(PRIVACY_GROUP,privacyGroupsListCombo.getValue());
            selectedPrivacyGroups.get(num).setText(privacyGroupsListCombo.getValue().getCode() + "String_Node_Str" + privacyGroupsListCombo.getValue().getTitle()+ "String_Node_Str"+ privacyGroupsPermissionsListCombo.getValue().getPermission());
            selectedPrivacyGroups.get(num).show();
            num++;
            selectedPrivacyGroupsIds.add(new Integer(privacyGroupsListCombo.getValue().getId()));
            privacyGroupsPerms.put(privacyGroupsListCombo.getValue(),PrivacyGroupPermissionEnum.translatePGPermission(privacyGroupsPermissionsListCombo.getValue().getPermission()));
          }
 else {
            MessageBox.alert(I18N.CONSTANTS.adminMaxAttempts(),I18N.CONSTANTS.adminMaxAttemptsProfiles(),null);
            ProfileSigmahForm.this.hide();
          }
        }
      }
    }
  }
);
  privacyGroupsAddSelectionGrid.setWidget(0,3,addButton);
  add(privacyGroupsAddSelectionGrid);
  if (profileToUpdate != null && profileToUpdate.getPrivacyGroups() != null) {
    Set<PrivacyGroupDTO> usedPrivacyGroups=profileToUpdate.getPrivacyGroups().keySet();
    for (    PrivacyGroupDTO usedPrivacyGroup : usedPrivacyGroups) {
      if (num < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER) {
        selectedPrivacyGroups.get(num).setData(PRIVACY_GROUP,usedPrivacyGroup);
        selectedPrivacyGroups.get(num).setText(usedPrivacyGroup.getCode() + "String_Node_Str" + usedPrivacyGroup.getTitle()+ "String_Node_Str"+ PrivacyGroupPermissionEnum.getName(profileToUpdate.getPrivacyGroups().get(usedPrivacyGroup)));
        selectedPrivacyGroups.get(num).show();
        num++;
      }
 else {
        MessageBox.alert("String_Node_Str","String_Node_Str",null);
        ProfileSigmahForm.this.hide();
      }
    }
  }
  for (  ClickableLabel selected : selectedPrivacyGroups.values()) {
    ProfileSigmahForm.this.add(selected);
  }
  final Button createButton=new Button(I18N.CONSTANTS.save());
  createButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      createProfile(callback);
    }
  }
);
  add(createButton);
}

Fixed version (ground truth):
public ProfileSigmahForm(Dispatcher dispatcher,UserLocalCache userCache,final AsyncCallback<CreateResult> callback,ProfileDTO profileToUpdate){
  this.dispatcher=dispatcher;
  this.profileToUpdate=profileToUpdate;
  UIConstants constants=GWT.create(UIConstants.class);
  FormLayout layout=new FormLayout();
  layout.setLabelWidth(LABEL_WIDTH);
  setLayout(layout);
  nameField=new TextField<String>();
  nameField.setFieldLabel(constants.adminProfilesName());
  nameField.setAllowBlank(false);
  if (profileToUpdate != null && !profileToUpdate.getName().isEmpty())   nameField.setValue(profileToUpdate.getName());
  add(nameField);
  checkGlobalPermissions=new ArrayList<CheckBoxGroup>();
  CheckBoxGroup checkGPGroup=new CheckBoxGroup();
  checkGPGroup.setOrientation(Orientation.VERTICAL);
  checkGPGroup.setFieldLabel(I18N.CONSTANTS.adminProfilesGlobalPermissions());
  String label="String_Node_Str";
  for (  GlobalPermissionEnum enumItem : GlobalPermissionEnum.values()) {
    label=GlobalPermissionEnum.getName(enumItem);
    CheckBox box=createCheckBox(enumItem.toString(),label);
    if (profileToUpdate != null && profileToUpdate.getGlobalPermissions() != null && profileToUpdate.getGlobalPermissions().contains(enumItem)) {
      box.setValue(true);
    }
    checkGPGroup.add(box);
  }
  checkGlobalPermissions.add(checkGPGroup);
  add(checkGPGroup);
  for (int i1=0; i1 < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER; i1++) {
    final ClickableLabel pglabel=new ClickableLabel();
    pglabel.hide();
    pglabel.addClickHandler(new ClickHandler(){
      @Override public void onClick(      ClickEvent arg0){
        pglabel.removeFromParent();
        selectedPrivacyGroupsIds.remove(new Integer(((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP)).getId()));
        if (privacyGroupsPerms.containsKey((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP))) {
        }
        privacyGroupsPerms.remove((PrivacyGroupDTO)pglabel.getData(PRIVACY_GROUP));
      }
    }
);
    selectedPrivacyGroups.put(i1,pglabel);
  }
  privacyGroupsPermissionsListCombo=new ComboBox<PrivacyGroupPermDTO>();
  privacyGroupsPermissionsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsPermissionsListCombo.setValueField("String_Node_Str");
  privacyGroupsPermissionsListCombo.setEditable(false);
  privacyGroupsPermissionsListCombo.setTriggerAction(TriggerAction.ALL);
  int j=0;
  ListStore<PrivacyGroupPermDTO> permsStore=new ListStore<PrivacyGroupPermDTO>();
  for (  PrivacyGroupPermissionEnum enumItem : PrivacyGroupPermissionEnum.values()) {
    j++;
    PrivacyGroupPermDTO perm=new PrivacyGroupPermDTO();
    perm.setId(j);
    perm.setPermission(PrivacyGroupPermissionEnum.getName(enumItem));
    if (!PrivacyGroupPermissionEnum.NONE.equals(enumItem))     permsStore.add(perm);
  }
  privacyGroupsPermissionsListCombo.setStore(permsStore);
  privacyGroupsListCombo=new ComboBox<PrivacyGroupDTO>();
  privacyGroupsListCombo.setDisplayField("String_Node_Str");
  privacyGroupsListCombo.setValueField("String_Node_Str");
  privacyGroupsListCombo.setEditable(false);
  privacyGroupsListCombo.setTriggerAction(TriggerAction.ALL);
  final ListStore<PrivacyGroupDTO> privacyGroupsStore=new ListStore<PrivacyGroupDTO>();
  dispatcher.execute(new GetPrivacyGroups(),null,new AsyncCallback<PrivacyGroupsListResult>(){
    @Override public void onFailure(    Throwable arg0){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminChoiceProblem());
    }
    @Override public void onSuccess(    PrivacyGroupsListResult result){
      privacyGroupsListCombo.setEmptyText(I18N.CONSTANTS.adminPrivacyGroupChoice());
      privacyGroupsStore.removeAll();
      if (result != null) {
        privacyGroupsStore.add(result.getList());
        privacyGroupsStore.commitChanges();
      }
    }
  }
);
  privacyGroupsListCombo.setStore(privacyGroupsStore);
  final Grid privacyGroupsAddSelectionGrid=new Grid(1,4);
  privacyGroupsAddSelectionGrid.getCellFormatter().setWidth(0,0,(LABEL_WIDTH + 5) + "String_Node_Str");
  privacyGroupsAddSelectionGrid.setCellPadding(0);
  privacyGroupsAddSelectionGrid.setCellSpacing(0);
  privacyGroupsAddSelectionGrid.setWidget(0,0,new LabelField(I18N.CONSTANTS.adminProfilesPrivacyGroups() + "String_Node_Str"));
  privacyGroupsAddSelectionGrid.setWidget(0,1,privacyGroupsListCombo);
  privacyGroupsAddSelectionGrid.setWidget(0,2,privacyGroupsPermissionsListCombo);
  privacyGroupsListCombo.setHideLabel(false);
  if (profileToUpdate != null && profileToUpdate.getPrivacyGroups() != null) {
    Set<PrivacyGroupDTO> usedPrivacyGroups=profileToUpdate.getPrivacyGroups().keySet();
    for (    PrivacyGroupDTO usedPrivacyGroup : usedPrivacyGroups) {
      selectedPrivacyGroupsIds.add(new Integer(usedPrivacyGroup.getId()));
      privacyGroupsPerms.put(usedPrivacyGroup,profileToUpdate.getPrivacyGroups().get(usedPrivacyGroup));
    }
  }
  final Button addButton=new Button(I18N.CONSTANTS.addItem());
  addButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      if (privacyGroupsListCombo.getValue() != null) {
        if (!selectedPrivacyGroupsIds.contains(new Integer(privacyGroupsListCombo.getValue().getId()))) {
          if (num < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER) {
            selectedPrivacyGroups.get(num).setData(PRIVACY_GROUP,privacyGroupsListCombo.getValue());
            selectedPrivacyGroups.get(num).setText(privacyGroupsListCombo.getValue().getCode() + "String_Node_Str" + privacyGroupsListCombo.getValue().getTitle()+ "String_Node_Str"+ privacyGroupsPermissionsListCombo.getValue().getPermission());
            selectedPrivacyGroups.get(num).show();
            num++;
            selectedPrivacyGroupsIds.add(new Integer(privacyGroupsListCombo.getValue().getId()));
            privacyGroupsPerms.put(privacyGroupsListCombo.getValue(),PrivacyGroupPermissionEnum.translatePGPermission(privacyGroupsPermissionsListCombo.getValue().getPermission()));
          }
 else {
            MessageBox.alert(I18N.CONSTANTS.adminMaxAttempts(),I18N.CONSTANTS.adminMaxAttemptsProfiles(),null);
            ProfileSigmahForm.this.hide();
          }
        }
      }
    }
  }
);
  privacyGroupsAddSelectionGrid.setWidget(0,3,addButton);
  add(privacyGroupsAddSelectionGrid);
  if (profileToUpdate != null && profileToUpdate.getPrivacyGroups() != null) {
    Set<PrivacyGroupDTO> usedPrivacyGroups=profileToUpdate.getPrivacyGroups().keySet();
    for (    PrivacyGroupDTO usedPrivacyGroup : usedPrivacyGroups) {
      if (num < MAX_PRIVACY_GROUPS_TENTATIVES_PER_USER) {
        selectedPrivacyGroups.get(num).setData(PRIVACY_GROUP,usedPrivacyGroup);
        selectedPrivacyGroups.get(num).setText(usedPrivacyGroup.getCode() + "String_Node_Str" + usedPrivacyGroup.getTitle()+ "String_Node_Str"+ PrivacyGroupPermissionEnum.getName(profileToUpdate.getPrivacyGroups().get(usedPrivacyGroup)));
        selectedPrivacyGroups.get(num).show();
        num++;
      }
 else {
        MessageBox.alert("String_Node_Str","String_Node_Str",null);
        ProfileSigmahForm.this.hide();
      }
    }
  }
  for (  ClickableLabel selected : selectedPrivacyGroups.values()) {
    ProfileSigmahForm.this.add(selected);
  }
  final Button createButton=new Button(I18N.CONSTANTS.save());
  createButton.addListener(Events.OnClick,new Listener<ButtonEvent>(){
    @Override public void handleEvent(    ButtonEvent be){
      createProfile(callback);
    }
  }
);
  add(createButton);
}