Program: 61068
Project: 61068
Buggy source:
/** 
 * Constructor.
 * @param basePage
 * @param window
 * @param roleTO
 * @param createFlag
 */
public RoleModalPage(final BasePage basePage,final ModalWindow window,final RoleTO roleTO,final boolean createFlag){
  super();
  if (!createFlag) {
    cloneOldRoleTO(roleTO);
  }
  final Form form=new Form("String_Node_Str");
  add(new Label("String_Node_Str",roleTO.getId() != 0 ? roleTO.getDisplayName() : "String_Node_Str"));
  form.setModel(new CompoundPropertyModel(roleTO));
  setupSchemaWrappers(createFlag,roleTO);
  final IModel<List<String>> derivedSchemaNames=new LoadableDetachableModel<List<String>>(){
    @Override protected List<String> load(){
      return schemaRestClient.getDerivedSchemaNames("String_Node_Str");
    }
  }
;
  final IModel<List<String>> virtualSchemaNames=new LoadableDetachableModel<List<String>>(){
    @Override protected List<String> load(){
      return schemaRestClient.getVirtualSchemaNames("String_Node_Str");
    }
  }
;
  final ListView roleAttributesView=new ListView("String_Node_Str",schemaWrappers){
    @Override protected void populateItem(    final ListItem item){
      final SchemaWrapper schemaWrapper=(SchemaWrapper)item.getDefaultModelObject();
      final SchemaTO schemaTO=schemaWrapper.getSchemaTO();
      item.add(new Label("String_Node_Str",schemaWrapper.getSchemaTO().getName()));
      item.add(new ListView("String_Node_Str",schemaWrapper.getValues()){
        Panel panel;
        @Override protected void populateItem(        final ListItem item){
          String mandatoryCondition=schemaTO.getMandatoryCondition();
          boolean required=false;
          if (mandatoryCondition.equalsIgnoreCase("String_Node_Str")) {
            required=true;
          }
          if (schemaTO.getType() == SchemaType.Boolean) {
            panel=new AjaxCheckBoxPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                return (String)item.getModelObject();
              }
              @Override public void setObject(              Serializable object){
                Boolean val=(Boolean)object;
                item.setModelObject(val.toString());
              }
            }
,required);
          }
 else           if (schemaTO.getType() == SchemaType.Date) {
            panel=new DateFieldPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                DateFormat formatter=new SimpleDateFormat(schemaTO.getConversionPattern());
                Date date=new Date();
                try {
                  String dateValue=(String)item.getModelObject();
                  if (!dateValue.equals("String_Node_Str")) {
                    date=formatter.parse(dateValue);
                  }
 else {
                    date=null;
                  }
                }
 catch (                ParseException e) {
                  LOG.error("String_Node_Str",e);
                }
                return date;
              }
              @Override public void setObject(              Serializable object){
                Date date=(Date)object;
                Format formatter=new SimpleDateFormat(schemaTO.getConversionPattern());
                String val=formatter.format(date);
                item.setModelObject(val);
              }
            }
,schemaTO.getConversionPattern(),required,schemaTO.isReadonly(),form);
          }
 else {
            panel=new AjaxTextFieldPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                return (String)item.getModelObject();
              }
              @Override public void setObject(              Serializable object){
                item.setModelObject((String)object);
              }
            }
,required);
          }
          item.add(panel);
        }
      }
);
      AjaxButton addButton=new IndicatingAjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
        @Override protected void onSubmit(        final AjaxRequestTarget target,        final Form form){
          schemaWrapper.getValues().add("String_Node_Str");
          target.addComponent(container);
        }
      }
;
      AjaxButton dropButton=new AjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
        @Override protected void onSubmit(        final AjaxRequestTarget target,        final Form form){
          schemaWrapper.getValues().remove(schemaWrapper.getValues().size() - 1);
          target.addComponent(container);
        }
        @Override protected IAjaxCallDecorator getAjaxCallDecorator(){
          return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()){
            @Override public CharSequence preDecorateScript(            CharSequence script){
              return "String_Node_Str" + getString("String_Node_Str") + "String_Node_Str"+ "String_Node_Str"+ script+ "String_Node_Str";
            }
          }
;
        }
      }
;
      if (schemaTO.getType() == SchemaType.Boolean) {
        addButton.setVisible(false);
        dropButton.setVisible(false);
      }
      addButton.setDefaultFormProcessing(false);
      addButton.setVisible(schemaTO.isMultivalue());
      dropButton.setDefaultFormProcessing(false);
      dropButton.setVisible(schemaTO.isMultivalue());
      if (schemaWrapper.getValues().size() == 1) {
        dropButton.setVisible(false);
      }
      item.add(addButton);
      item.add(dropButton);
    }
  }
;
  form.add(roleAttributesView);
  form.add((new DerivedAttributesForm("String_Node_Str")).build(this,roleTO,derivedSchemaNames));
  form.add((new VirtualAttributesForm("String_Node_Str")).build(this,roleTO,virtualSchemaNames));
  ListModel<ResourceTO> selectedResources=new ListModel<ResourceTO>();
  selectedResources.setObject(getSelectedResources(roleTO));
  ListModel<ResourceTO> availableResources=new ListModel<ResourceTO>();
  availableResources.setObject(getAvailableResources(roleTO));
  final Palette<ResourceTO> resourcesPalette=new Palette("String_Node_Str",selectedResources,availableResources,new ChoiceRenderer("String_Node_Str","String_Node_Str"),8,false);
  form.add(resourcesPalette);
  ListModel<String> selectedEntitlements=new ListModel<String>(roleTO.getEntitlements());
  ListModel<String> availableEntitlements=new ListModel<String>(entitlementRestClient.getAllEntitlements());
  final Palette<String> entitlementsPalette=new Palette("String_Node_Str",selectedEntitlements,availableEntitlements,new StringChoiceRenderer(),20,false);
  form.add(entitlementsPalette);
  container=new WebMarkupContainer("String_Node_Str");
  container.add(roleAttributesView);
  container.setOutputMarkupId(true);
  form.add(container);
  TextField name=new TextField("String_Node_Str");
  name.setRequired(true);
  container.add(name);
  submit=new IndicatingAjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
    @Override protected void onSubmit(    final AjaxRequestTarget target,    final Form form){
      RoleTO roleTO=(RoleTO)form.getDefaultModelObject();
      boolean res=false;
      try {
        Set<String> resourcesSet=new HashSet<String>(resourcesPalette.getModelCollection().size());
        for (        ResourceTO resourceTO : resourcesPalette.getModelCollection()) {
          resourcesSet.add(resourceTO.getName());
        }
        roleTO.setResources(resourcesSet);
        List<String> entitlementList=new ArrayList<String>(entitlementsPalette.getModelCollection().size());
        for (        String entitlement : entitlementsPalette.getModelCollection()) {
          entitlementList.add(entitlement);
        }
        roleTO.setEntitlements(entitlementList);
        roleTO.setAttributes(getRoleAttributes());
        if (createFlag) {
          roleRestClient.createRole(roleTO);
        }
 else {
          setupRoleMod(roleTO);
          if (roleMod != null) {
            roleRestClient.updateRole(roleMod);
          }
        }
        ((Roles)basePage).setOperationResult(true);
        window.close(target);
      }
 catch (      Exception e) {
        error(getString("String_Node_Str") + "String_Node_Str" + e.getMessage());
      }
    }
    @Override protected void onError(    final AjaxRequestTarget target,    final Form form){
      target.addComponent(feedbackPanel);
    }
  }
;
  String allowedRoles;
  if (createFlag) {
    allowedRoles=xmlRolesReader.getAllAllowedRoles("String_Node_Str","String_Node_Str");
  }
 else {
    allowedRoles=xmlRolesReader.getAllAllowedRoles("String_Node_Str","String_Node_Str");
  }
  MetaDataRoleAuthorizationStrategy.authorize(submit,ENABLE,allowedRoles);
  form.add(submit);
  add(form);
}

Fixed version (ground truth):
/** 
 * Constructor.
 * @param basePage
 * @param window
 * @param roleTO
 * @param createFlag
 */
public RoleModalPage(final BasePage basePage,final ModalWindow window,final RoleTO roleTO,final boolean createFlag){
  super();
  if (!createFlag) {
    cloneOldRoleTO(roleTO);
  }
  final Form form=new Form("String_Node_Str");
  add(new Label("String_Node_Str",roleTO.getId() != 0 ? roleTO.getDisplayName() : "String_Node_Str"));
  form.setModel(new CompoundPropertyModel(roleTO));
  setupSchemaWrappers(createFlag,roleTO);
  final IModel<List<String>> derivedSchemaNames=new LoadableDetachableModel<List<String>>(){
    @Override protected List<String> load(){
      return schemaRestClient.getDerivedSchemaNames("String_Node_Str");
    }
  }
;
  final IModel<List<String>> virtualSchemaNames=new LoadableDetachableModel<List<String>>(){
    @Override protected List<String> load(){
      return schemaRestClient.getVirtualSchemaNames("String_Node_Str");
    }
  }
;
  final ListView roleAttributesView=new ListView("String_Node_Str",schemaWrappers){
    @Override protected void populateItem(    final ListItem item){
      final SchemaWrapper schemaWrapper=(SchemaWrapper)item.getDefaultModelObject();
      final SchemaTO schemaTO=schemaWrapper.getSchemaTO();
      item.add(new Label("String_Node_Str",schemaWrapper.getSchemaTO().getName()));
      item.add(new ListView("String_Node_Str",schemaWrapper.getValues()){
        Panel panel;
        @Override protected void populateItem(        final ListItem item){
          String mandatoryCondition=schemaTO.getMandatoryCondition();
          boolean required=false;
          if (mandatoryCondition.equalsIgnoreCase("String_Node_Str")) {
            required=true;
          }
          if (schemaTO.getType() == SchemaType.Boolean) {
            panel=new AjaxCheckBoxPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                return (String)item.getModelObject();
              }
              @Override public void setObject(              Serializable object){
                Boolean val=(Boolean)object;
                item.setModelObject(val.toString());
              }
            }
,required);
          }
 else           if (schemaTO.getType() == SchemaType.Date) {
            panel=new DateFieldPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                DateFormat formatter=new SimpleDateFormat(schemaTO.getConversionPattern());
                Date date=new Date();
                try {
                  String dateValue=(String)item.getModelObject();
                  if (!dateValue.equals("String_Node_Str")) {
                    date=formatter.parse(dateValue);
                  }
 else {
                    date=null;
                  }
                }
 catch (                ParseException e) {
                  LOG.error("String_Node_Str",e);
                }
                return date;
              }
              @Override public void setObject(              Serializable object){
                Date date=(Date)object;
                Format formatter=new SimpleDateFormat(schemaTO.getConversionPattern());
                String val=formatter.format(date);
                item.setModelObject(val);
              }
            }
,schemaTO.getConversionPattern(),required,schemaTO.isReadonly(),form);
          }
 else {
            panel=new AjaxTextFieldPanel("String_Node_Str",schemaTO.getName(),new Model(){
              @Override public Serializable getObject(){
                return (String)item.getModelObject();
              }
              @Override public void setObject(              Serializable object){
                item.setModelObject((String)object);
              }
            }
,required);
          }
          item.add(panel);
        }
      }
);
      AjaxButton addButton=new IndicatingAjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
        @Override protected void onSubmit(        final AjaxRequestTarget target,        final Form form){
          schemaWrapper.getValues().add("String_Node_Str");
          target.addComponent(container);
        }
      }
;
      AjaxButton dropButton=new AjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
        @Override protected void onSubmit(        final AjaxRequestTarget target,        final Form form){
          schemaWrapper.getValues().remove(schemaWrapper.getValues().size() - 1);
          target.addComponent(container);
        }
        @Override protected IAjaxCallDecorator getAjaxCallDecorator(){
          return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()){
            @Override public CharSequence preDecorateScript(            CharSequence script){
              return "String_Node_Str" + getString("String_Node_Str") + "String_Node_Str"+ "String_Node_Str"+ script+ "String_Node_Str";
            }
          }
;
        }
      }
;
      if (schemaTO.getType() == SchemaType.Boolean) {
        addButton.setVisible(false);
        dropButton.setVisible(false);
      }
      addButton.setDefaultFormProcessing(false);
      addButton.setVisible(schemaTO.isMultivalue());
      dropButton.setDefaultFormProcessing(false);
      dropButton.setVisible(schemaTO.isMultivalue());
      if (schemaWrapper.getValues().size() == 1) {
        dropButton.setVisible(false);
      }
      item.add(addButton);
      item.add(dropButton);
    }
  }
;
  form.add(roleAttributesView);
  final CheckBox inheritAttributes=new CheckBox("String_Node_Str");
  inheritAttributes.setOutputMarkupId(true);
  form.add(inheritAttributes);
  form.add((new DerivedAttributesForm("String_Node_Str")).build(this,roleTO,derivedSchemaNames));
  final CheckBox inheritDerivedAttributes=new CheckBox("String_Node_Str");
  inheritDerivedAttributes.setOutputMarkupId(true);
  form.add(inheritDerivedAttributes);
  form.add((new VirtualAttributesForm("String_Node_Str")).build(this,roleTO,virtualSchemaNames));
  final CheckBox inheritVirtualAttributes=new CheckBox("String_Node_Str");
  inheritVirtualAttributes.setOutputMarkupId(true);
  form.add(inheritVirtualAttributes);
  ListModel<ResourceTO> selectedResources=new ListModel<ResourceTO>();
  selectedResources.setObject(getSelectedResources(roleTO));
  ListModel<ResourceTO> availableResources=new ListModel<ResourceTO>();
  availableResources.setObject(getAvailableResources(roleTO));
  final Palette<ResourceTO> resourcesPalette=new Palette("String_Node_Str",selectedResources,availableResources,new ChoiceRenderer("String_Node_Str","String_Node_Str"),8,false);
  form.add(resourcesPalette);
  ListModel<String> selectedEntitlements=new ListModel<String>(roleTO.getEntitlements());
  ListModel<String> availableEntitlements=new ListModel<String>(entitlementRestClient.getAllEntitlements());
  final Palette<String> entitlementsPalette=new Palette("String_Node_Str",selectedEntitlements,availableEntitlements,new StringChoiceRenderer(),20,false);
  form.add(entitlementsPalette);
  container=new WebMarkupContainer("String_Node_Str");
  container.add(roleAttributesView);
  container.setOutputMarkupId(true);
  form.add(container);
  TextField name=new TextField("String_Node_Str");
  name.setRequired(true);
  container.add(name);
  submit=new IndicatingAjaxButton("String_Node_Str",new Model(getString("String_Node_Str"))){
    @Override protected void onSubmit(    final AjaxRequestTarget target,    final Form form){
      RoleTO roleTO=(RoleTO)form.getDefaultModelObject();
      boolean res=false;
      try {
        Set<String> resourcesSet=new HashSet<String>(resourcesPalette.getModelCollection().size());
        for (        ResourceTO resourceTO : resourcesPalette.getModelCollection()) {
          resourcesSet.add(resourceTO.getName());
        }
        roleTO.setResources(resourcesSet);
        List<String> entitlementList=new ArrayList<String>(entitlementsPalette.getModelCollection().size());
        for (        String entitlement : entitlementsPalette.getModelCollection()) {
          entitlementList.add(entitlement);
        }
        roleTO.setEntitlements(entitlementList);
        roleTO.setAttributes(getRoleAttributes());
        if (createFlag) {
          roleRestClient.createRole(roleTO);
        }
 else {
          setupRoleMod(roleTO);
          if (roleMod != null) {
            roleRestClient.updateRole(roleMod);
          }
        }
        ((Roles)basePage).setOperationResult(true);
        window.close(target);
      }
 catch (      Exception e) {
        error(getString("String_Node_Str") + "String_Node_Str" + e.getMessage());
      }
    }
    @Override protected void onError(    final AjaxRequestTarget target,    final Form form){
      target.addComponent(feedbackPanel);
    }
  }
;
  String allowedRoles;
  if (createFlag) {
    allowedRoles=xmlRolesReader.getAllAllowedRoles("String_Node_Str","String_Node_Str");
  }
 else {
    allowedRoles=xmlRolesReader.getAllAllowedRoles("String_Node_Str","String_Node_Str");
  }
  MetaDataRoleAuthorizationStrategy.authorize(submit,ENABLE,allowedRoles);
  form.add(submit);
  add(form);
}