Program: 29313
Project: 29313
Buggy source:
/** 
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and the values the parameter values
 * @param context information
 */
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  if (securityMapName == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  Collection<ConnectorConnectionPool> ccPools=domain.getResources().getResources(ConnectorConnectionPool.class);
  if (!doesPoolNameExist(poolName,ccPools)) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",poolName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (!doesMapNameExist(poolName,securityMapName,ccPools)) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",securityMapName,poolName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  List<SecurityMap> maps=getAllSecurityMapsForPool(poolName,ccPools);
  if (addPrincipals != null && removePrincipals != null) {
    for (    String ap : addPrincipals) {
      for (      String rp : removePrincipals) {
        if (rp.equals(ap)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",ap));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
    }
  }
  if (addUserGroups != null && removeUserGroups != null) {
    for (    String aug : addUserGroups) {
      for (      String rug : removeUserGroups) {
        if (rug.equals(aug)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",aug));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
    }
  }
  if (addPrincipals != null) {
    for (    String principal : addPrincipals) {
      if (isPrincipalExisting(principal,maps)) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (addUserGroups != null) {
    for (    String userGroup : addUserGroups) {
      if (isUserGroupExisting(userGroup,maps)) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  SecurityMap map=getSecurityMap(securityMapName,poolName,ccPools);
  final List<String> existingPrincipals=new ArrayList(map.getPrincipal());
  final List<String> existingUserGroups=new ArrayList(map.getUserGroup());
  if (existingPrincipals.isEmpty() && addPrincipals != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str" + "String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (existingUserGroups.isEmpty() && addUserGroups != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str" + "String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (removePrincipals != null) {
    boolean principalExists=true;
    String principal=null;
    if (existingPrincipals != null) {
      for (      String p : removePrincipals) {
        if (!existingPrincipals.contains(p)) {
          principalExists=false;
          principal=p;
          break;
        }
      }
    }
 else {
      principalExists=false;
    }
    if (!principalExists) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (removeUserGroups != null) {
    boolean userGroupExists=true;
    String userGroup=null;
    if (existingUserGroups != null) {
      for (      String ug : removeUserGroups) {
        if (!existingUserGroups.contains(ug)) {
          userGroupExists=false;
          userGroup=ug;
          break;
        }
      }
    }
 else {
      userGroupExists=false;
    }
    if (!userGroupExists) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (addPrincipals == null && addUserGroups == null) {
    boolean principalsEmpty=false;
    boolean userGroupsEmpty=false;
    if (removePrincipals == null && existingPrincipals.isEmpty()) {
      principalsEmpty=true;
    }
    if (removeUserGroups == null && existingUserGroups.isEmpty()) {
      userGroupsEmpty=true;
    }
    if ((removePrincipals != null) && (removePrincipals.size() == existingPrincipals.size())) {
      principalsEmpty=true;
    }
    if ((removeUserGroups != null) && (removeUserGroups.size() == existingUserGroups.size())) {
      userGroupsEmpty=true;
    }
    if (userGroupsEmpty && principalsEmpty) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (addPrincipals != null) {
    for (    String principal : addPrincipals) {
      if (!existingPrincipals.contains(principal)) {
        existingPrincipals.add(principal);
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (removePrincipals != null) {
    for (    String principal : removePrincipals) {
      existingPrincipals.remove(principal);
    }
  }
  if (addUserGroups != null) {
    for (    String userGroup : addUserGroups) {
      if (!existingUserGroups.contains(userGroup)) {
        existingUserGroups.add(userGroup);
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (removeUserGroups != null) {
    for (    String userGroup : removeUserGroups) {
      existingUserGroups.remove(userGroup);
    }
  }
  BackendPrincipal backendPrincipal=map.getBackendPrincipal();
  try {
    ConfigSupport.apply(new ConfigCode(){
      public Object run(      ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
        SecurityMap sm=(SecurityMap)params[0];
        BackendPrincipal bp=(BackendPrincipal)params[1];
        if (existingPrincipals != null) {
          sm.getPrincipal().clear();
          for (          String principal : existingPrincipals) {
            sm.getPrincipal().add(principal);
          }
        }
        if (existingUserGroups != null) {
          sm.getUserGroup().clear();
          for (          String userGroup : existingUserGroups) {
            sm.getUserGroup().add(userGroup);
          }
        }
        if (mappedusername != null && !mappedusername.isEmpty()) {
          bp.setUserName(mappedusername);
        }
        if (mappedpassword != null && !mappedpassword.isEmpty()) {
          bp.setPassword(mappedpassword);
        }
        return sm;
      }
    }
,map,backendPrincipal);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
  }
 catch (  TransactionFailure tfe) {
    Object params[]={securityMapName,poolName};
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",params) + "String_Node_Str" + tfe.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(tfe);
  }
}

Fixed version (ground truth):
/** 
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and the values the parameter values
 * @param context information
 */
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  if (securityMapName == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  Collection<ConnectorConnectionPool> ccPools=domain.getResources().getResources(ConnectorConnectionPool.class);
  if (!doesPoolNameExist(poolName,ccPools)) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",poolName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (!doesMapNameExist(poolName,securityMapName,ccPools)) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",securityMapName,poolName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  List<SecurityMap> maps=getAllSecurityMapsForPool(poolName,ccPools);
  if (addPrincipals != null && removePrincipals != null) {
    for (    String ap : addPrincipals) {
      for (      String rp : removePrincipals) {
        if (rp.equals(ap)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",ap));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
    }
  }
  if (addUserGroups != null && removeUserGroups != null) {
    for (    String aug : addUserGroups) {
      for (      String rug : removeUserGroups) {
        if (rug.equals(aug)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",aug));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
    }
  }
  if (addPrincipals != null) {
    for (    String principal : addPrincipals) {
      if (isPrincipalExisting(principal,maps)) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (addUserGroups != null) {
    for (    String userGroup : addUserGroups) {
      if (isUserGroupExisting(userGroup,maps)) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  SecurityMap map=getSecurityMap(securityMapName,poolName,ccPools);
  final List<String> existingPrincipals=new ArrayList(map.getPrincipal());
  final List<String> existingUserGroups=new ArrayList(map.getUserGroup());
  if (existingPrincipals.isEmpty() && addPrincipals != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str" + "String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (existingUserGroups.isEmpty() && addUserGroups != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str" + "String_Node_Str","String_Node_Str"));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  if (removePrincipals != null) {
    boolean principalExists=true;
    String principal=null;
    for (    String p : removePrincipals) {
      if (!existingPrincipals.contains(p)) {
        principalExists=false;
        principal=p;
        break;
      }
    }
    if (!principalExists) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (removeUserGroups != null) {
    boolean userGroupExists=true;
    String userGroup=null;
    for (    String ug : removeUserGroups) {
      if (!existingUserGroups.contains(ug)) {
        userGroupExists=false;
        userGroup=ug;
        break;
      }
    }
    if (!userGroupExists) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (addPrincipals == null && addUserGroups == null) {
    boolean principalsEmpty=false;
    boolean userGroupsEmpty=false;
    if (removePrincipals == null && existingPrincipals.isEmpty()) {
      principalsEmpty=true;
    }
    if (removeUserGroups == null && existingUserGroups.isEmpty()) {
      userGroupsEmpty=true;
    }
    if ((removePrincipals != null) && (removePrincipals.size() == existingPrincipals.size())) {
      principalsEmpty=true;
    }
    if ((removeUserGroups != null) && (removeUserGroups.size() == existingUserGroups.size())) {
      userGroupsEmpty=true;
    }
    if (userGroupsEmpty && principalsEmpty) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  if (addPrincipals != null) {
    for (    String principal : addPrincipals) {
      if (!existingPrincipals.contains(principal)) {
        existingPrincipals.add(principal);
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",principal,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (removePrincipals != null) {
    for (    String principal : removePrincipals) {
      existingPrincipals.remove(principal);
    }
  }
  if (addUserGroups != null) {
    for (    String userGroup : addUserGroups) {
      if (!existingUserGroups.contains(userGroup)) {
        existingUserGroups.add(userGroup);
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userGroup,poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  if (removeUserGroups != null) {
    for (    String userGroup : removeUserGroups) {
      existingUserGroups.remove(userGroup);
    }
  }
  BackendPrincipal backendPrincipal=map.getBackendPrincipal();
  try {
    ConfigSupport.apply(new ConfigCode(){
      public Object run(      ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
        SecurityMap sm=(SecurityMap)params[0];
        BackendPrincipal bp=(BackendPrincipal)params[1];
        if (existingPrincipals != null) {
          sm.getPrincipal().clear();
          for (          String principal : existingPrincipals) {
            sm.getPrincipal().add(principal);
          }
        }
        if (existingUserGroups != null) {
          sm.getUserGroup().clear();
          for (          String userGroup : existingUserGroups) {
            sm.getUserGroup().add(userGroup);
          }
        }
        if (mappedusername != null && !mappedusername.isEmpty()) {
          bp.setUserName(mappedusername);
        }
        if (mappedpassword != null && !mappedpassword.isEmpty()) {
          bp.setPassword(mappedpassword);
        }
        return sm;
      }
    }
,map,backendPrincipal);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
  }
 catch (  TransactionFailure tfe) {
    Object params[]={securityMapName,poolName};
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",params) + "String_Node_Str" + tfe.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(tfe);
  }
}