Program: 69898
Project: 69898
Buggy source:
/** 
 * creates the custom formLayoutContainer and adds a form-component for every PolicyWrapper, according to its type.
 */
protected void initPolicyUI(){
  String template=Util.getPackageVelocityRoot(this.getClass()) + "String_Node_Str";
  for (  PolicyWrapper policyWrapper : policyWrappers) {
    String cmpName=policyWrapper.getComponentName();
    if (cmpName != null && flc.getFormComponent(cmpName) != null) {
      flc.remove(cmpName);
    }
    cmpName=UUID.randomUUID().toString();
    policyWrapper.setComponentName(cmpName);
    FormLayoutContainer container=FormLayoutContainer.createCustomFormLayout(cmpName,getTranslator(),template);
    container.contextPut("String_Node_Str",policyWrapper);
    container.setRootForm(mainForm);
    SingleSelection type=uifactory.addDropdownSingleselect("String_Node_Str" + cmpName,"String_Node_Str",container,targetKeys,targetValues,null);
    type.addActionListener(this,FormEvent.ONCHANGE);
    type.setUserObject(policyWrapper);
    if (policyWrapper.getType() != null) {
      type.select(policyWrapper.getType().name(),true);
switch (policyWrapper.getType()) {
case user:
        Map<String,String> initialUsers=policyWrapper.getIdentitiesValue();
      TextBoxListElement userListBox=uifactory.addTextBoxListElement("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",initialUsers,container,getTranslator());
    userListBox.setUserObject(policyWrapper);
  userListBox.setMapperProvider(new UserMapperProvider());
userListBox.setAllowNewValues(false);
userListBox.setAllowDuplicates(false);
userListBox.setMaxResults(15);
policyWrapper.setUserListBox(userListBox);
break;
case group:
Map<String,String> initialGroups=policyWrapper.getGroupsValues();
TextBoxListElement groupListBox=uifactory.addTextBoxListElement("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",initialGroups,container,getTranslator());
groupListBox.setUserObject(policyWrapper);
groupListBox.setMapperProvider(new GroupMapperProvider());
groupListBox.setAllowNewValues(false);
groupListBox.setAllowDuplicates(false);
groupListBox.setMaxResults(15);
policyWrapper.setGroupListBox(groupListBox);
break;
case invitation:
Invitation invitation=policyWrapper.getInvitation();
if (invitation == null) {
invitation=securityManager.createAndPersistInvitation();
policyWrapper.setInvitation(invitation);
}
FormLayoutContainer invitationContainer=FormLayoutContainer.createDefaultFormLayout("String_Node_Str" + cmpName,getTranslator());
invitationContainer.contextPut("String_Node_Str",policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("String_Node_Str" + cmpName,invitationContainer);
uifactory.addSpacerElement("String_Node_Str" + cmpName,invitationContainer,true);
TextElement firstNameEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",64,invitation.getFirstName(),invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("String_Node_Str");
TextElement lastNameEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",64,invitation.getLastName(),invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("String_Node_Str");
TextElement mailEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",128,invitation.getMail(),invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("String_Node_Str");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers=securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
Identity currentIdentity=userManager.findIdentityByEmail(invitation.getMail());
if (currentIdentity != null && securityManager.isIdentityInSecurityGroup(currentIdentity,allUsers)) {
mailEl.setErrorKey("String_Node_Str",new String[]{invitation.getMail()});
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link=getInvitationLink(invitation,map);
StaticTextElement linkEl=uifactory.addStaticTextElement("String_Node_Str" + cmpName,link,invitationContainer);
linkEl.setLabel("String_Node_Str",null);
break;
case allusers:
String text=translate("String_Node_Str");
uifactory.addStaticTextElement("String_Node_Str" + cmpName,text,container);
break;
}
}
if (policyWrapper instanceof TutorPolicyWrapper) {
String text=translate("String_Node_Str");
uifactory.addStaticTextElement("String_Node_Str" + cmpName,text,container);
}
 else {
DateChooser fromChooser=uifactory.addDateChooser("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",container);
fromChooser.setDate(policyWrapper.getFrom());
fromChooser.setValidDateCheck("String_Node_Str");
policyWrapper.setFromChooser(fromChooser);
DateChooser toChooser=uifactory.addDateChooser("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",container);
toChooser.setDate(policyWrapper.getTo());
toChooser.setValidDateCheck("String_Node_Str");
policyWrapper.setToChooser(toChooser);
FormLink addLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_SMALL);
addLink.setUserObject(policyWrapper);
FormLink removeLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_SMALL);
removeLink.setUserObject(policyWrapper);
if (!policyWrapper.getType().equals(EPMapPolicy.Type.allusers)) {
FormLink inviteLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_XSMALL);
inviteLink.setUserObject(policyWrapper);
inviteLink.setEnabled(!policyWrapper.isInvitationSend());
}
StaticTextElement genErrorPanel=uifactory.addStaticTextElement("String_Node_Str" + cmpName,"String_Node_Str",container);
genErrorPanel.setUserObject(policyWrapper);
}
policyWrapper.setComponentName(cmpName);
flc.add(container);
flc.contextPut("String_Node_Str",policyWrapper);
}
flc.contextPut("String_Node_Str",policyWrappers);
}

Fixed version (ground truth):
/** 
 * creates the custom formLayoutContainer and adds a form-component for every PolicyWrapper, according to its type.
 */
protected void initPolicyUI(){
  String template=Util.getPackageVelocityRoot(this.getClass()) + "String_Node_Str";
  for (  PolicyWrapper policyWrapper : policyWrappers) {
    String cmpName=policyWrapper.getComponentName();
    if (cmpName != null && flc.getFormComponent(cmpName) != null) {
      flc.remove(cmpName);
    }
    cmpName=UUID.randomUUID().toString();
    policyWrapper.setComponentName(cmpName);
    FormLayoutContainer container=FormLayoutContainer.createCustomFormLayout(cmpName,getTranslator(),template);
    container.contextPut("String_Node_Str",policyWrapper);
    container.setRootForm(mainForm);
    if (policyWrapper.getType() != null) {
      SingleSelection type=uifactory.addDropdownSingleselect("String_Node_Str" + cmpName,"String_Node_Str",container,targetKeys,targetValues,null);
      type.addActionListener(this,FormEvent.ONCHANGE);
      type.setUserObject(policyWrapper);
      type.select(policyWrapper.getType().name(),true);
switch (policyWrapper.getType()) {
case user:
        Map<String,String> initialUsers=policyWrapper.getIdentitiesValue();
      TextBoxListElement userListBox=uifactory.addTextBoxListElement("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",initialUsers,container,getTranslator());
    userListBox.setUserObject(policyWrapper);
  userListBox.setMapperProvider(new UserMapperProvider());
userListBox.setAllowNewValues(false);
userListBox.setAllowDuplicates(false);
userListBox.setMaxResults(15);
policyWrapper.setUserListBox(userListBox);
break;
case group:
Map<String,String> initialGroups=policyWrapper.getGroupsValues();
TextBoxListElement groupListBox=uifactory.addTextBoxListElement("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",initialGroups,container,getTranslator());
groupListBox.setUserObject(policyWrapper);
groupListBox.setMapperProvider(new GroupMapperProvider());
groupListBox.setAllowNewValues(false);
groupListBox.setAllowDuplicates(false);
groupListBox.setMaxResults(15);
policyWrapper.setGroupListBox(groupListBox);
break;
case invitation:
Invitation invitation=policyWrapper.getInvitation();
if (invitation == null) {
invitation=securityManager.createAndPersistInvitation();
policyWrapper.setInvitation(invitation);
}
FormLayoutContainer invitationContainer=FormLayoutContainer.createDefaultFormLayout("String_Node_Str" + cmpName,getTranslator());
invitationContainer.contextPut("String_Node_Str",policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("String_Node_Str" + cmpName,invitationContainer);
uifactory.addSpacerElement("String_Node_Str" + cmpName,invitationContainer,true);
TextElement firstNameEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",64,invitation.getFirstName(),invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("String_Node_Str");
TextElement lastNameEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",64,invitation.getLastName(),invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("String_Node_Str");
TextElement mailEl=uifactory.addTextElement("String_Node_Str" + cmpName,"String_Node_Str",128,invitation.getMail(),invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("String_Node_Str");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers=securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
Identity currentIdentity=userManager.findIdentityByEmail(invitation.getMail());
if (currentIdentity != null && securityManager.isIdentityInSecurityGroup(currentIdentity,allUsers)) {
mailEl.setErrorKey("String_Node_Str",new String[]{invitation.getMail()});
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link=getInvitationLink(invitation,map);
StaticTextElement linkEl=uifactory.addStaticTextElement("String_Node_Str" + cmpName,link,invitationContainer);
linkEl.setLabel("String_Node_Str",null);
break;
case allusers:
String text=translate("String_Node_Str");
uifactory.addStaticTextElement("String_Node_Str" + cmpName,text,container);
break;
}
}
if (policyWrapper instanceof TutorPolicyWrapper) {
String text=translate("String_Node_Str");
uifactory.addStaticTextElement("String_Node_Str" + cmpName,text,container);
}
 else {
DateChooser fromChooser=uifactory.addDateChooser("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",container);
fromChooser.setDate(policyWrapper.getFrom());
fromChooser.setValidDateCheck("String_Node_Str");
policyWrapper.setFromChooser(fromChooser);
DateChooser toChooser=uifactory.addDateChooser("String_Node_Str" + cmpName,"String_Node_Str","String_Node_Str",container);
toChooser.setDate(policyWrapper.getTo());
toChooser.setValidDateCheck("String_Node_Str");
policyWrapper.setToChooser(toChooser);
FormLink addLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_SMALL);
addLink.setUserObject(policyWrapper);
FormLink removeLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_SMALL);
removeLink.setUserObject(policyWrapper);
if (!policyWrapper.getType().equals(EPMapPolicy.Type.allusers)) {
FormLink inviteLink=uifactory.addFormLink("String_Node_Str" + cmpName,"String_Node_Str",null,container,Link.BUTTON_XSMALL);
inviteLink.setUserObject(policyWrapper);
inviteLink.setEnabled(!policyWrapper.isInvitationSend());
}
StaticTextElement genErrorPanel=uifactory.addStaticTextElement("String_Node_Str" + cmpName,"String_Node_Str",container);
genErrorPanel.setUserObject(policyWrapper);
}
policyWrapper.setComponentName(cmpName);
flc.add(container);
flc.contextPut("String_Node_Str",policyWrapper);
}
flc.contextPut("String_Node_Str",policyWrappers);
}