Program: 29154
Project: 29154
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();
  Config tmp=null;
  try {
    tmp=configs.getConfigByName(target);
  }
 catch (  Exception ex) {
  }
  if (tmp != null) {
    config=tmp;
  }
  if (tmp == null) {
    Server targetServer=domain.getServerNamed(target);
    if (targetServer != null) {
      config=domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster=domain.getClusterNamed(target);
    if (cluster != null) {
      config=domain.getConfigNamed(cluster.getConfigRef());
    }
  }
  final SecurityService securityService=config.getSecurityService();
  AuthRealm fileAuthRealm=null;
  if (authRealmName == null)   authRealmName=securityService.getDefaultRealm();
  for (  AuthRealm authRealm : securityService.getAuthRealm()) {
    if (authRealm.getName().equals(authRealmName)) {
      fileAuthRealm=authRealm;
      break;
    }
  }
  if (fileAuthRealm == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String fileRealmClassName=fileAuthRealm.getClassname();
  if (fileRealmClassName != null && !fileRealmClassName.equals("String_Node_Str")) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",fileRealmClassName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String keyFile=null;
  for (  Property fileProp : fileAuthRealm.getProperty()) {
    if (fileProp.getName().equals("String_Node_Str"))     keyFile=fileProp.getValue();
  }
  final String kf=keyFile;
  if (keyFile == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  boolean exists=(new File(kf)).exists();
  if (!exists) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{kf,authRealmName}));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  final String password=userpassword;
  if (password == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",userName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  secureAdmin=domain.getSecureAdmin();
  if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (authRealmName.equals(adminService.getAuthRealmName()))) {
    if ((password == null) || (password.isEmpty())) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  try {
    ConfigSupport.apply(new SingleConfigCode<SecurityService>(){
      public Object run(      SecurityService param) throws PropertyVetoException, TransactionFailure {
        try {
          realmsManager.createRealms(config);
          refreshRealm(config.getName(),authRealmName);
          final FileRealm fr=(FileRealm)realmsManager.getFromLoadedRealms(config.getName(),authRealmName);
          CreateFileUser.handleAdminGroup(authRealmName,groups);
          String[] groups1=groups.toArray(new String[groups.size()]);
          try {
            fr.addUser(userName,password.toCharArray(),groups1);
          }
 catch (          BadRealmException br) {
            if (se != null && se.isDas()) {
              throw new BadRealmException(br);
            }
          }
          fr.persist();
          report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
 catch (        Exception e) {
          String localalizedErrorMsg=(e.getLocalizedMessage() == null) ? "String_Node_Str" : e.getLocalizedMessage();
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userName,authRealmName) + "String_Node_Str" + localalizedErrorMsg);
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setFailureCause(e);
        }
        return null;
      }
    }
,securityService);
  }
 catch (  Exception e) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userName,authRealmName) + "String_Node_Str" + e.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(e);
  }
}

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();
  Config tmp=null;
  try {
    tmp=configs.getConfigByName(target);
  }
 catch (  Exception ex) {
  }
  if (tmp != null) {
    config=tmp;
  }
  if (tmp == null) {
    Server targetServer=domain.getServerNamed(target);
    if (targetServer != null) {
      config=domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster=domain.getClusterNamed(target);
    if (cluster != null) {
      config=domain.getConfigNamed(cluster.getConfigRef());
    }
  }
  final SecurityService securityService=config.getSecurityService();
  AuthRealm fileAuthRealm=null;
  if (authRealmName == null)   authRealmName=securityService.getDefaultRealm();
  for (  AuthRealm authRealm : securityService.getAuthRealm()) {
    if (authRealm.getName().equals(authRealmName)) {
      fileAuthRealm=authRealm;
      break;
    }
  }
  if (fileAuthRealm == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String fileRealmClassName=fileAuthRealm.getClassname();
  if (fileRealmClassName != null && !fileRealmClassName.equals("String_Node_Str")) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",fileRealmClassName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String keyFile=null;
  for (  Property fileProp : fileAuthRealm.getProperty()) {
    if (fileProp.getName().equals("String_Node_Str"))     keyFile=fileProp.getValue();
  }
  final String kf=keyFile;
  if (keyFile == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  boolean exists=(new File(kf)).exists();
  if (!exists) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{kf,authRealmName}));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  final String password=userpassword;
  if (password == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",userName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  secureAdmin=domain.getSecureAdmin();
  if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (authRealmName.equals(adminService.getAuthRealmName()))) {
    if (password.isEmpty()) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  try {
    ConfigSupport.apply(new SingleConfigCode<SecurityService>(){
      public Object run(      SecurityService param) throws PropertyVetoException, TransactionFailure {
        try {
          realmsManager.createRealms(config);
          refreshRealm(config.getName(),authRealmName);
          final FileRealm fr=(FileRealm)realmsManager.getFromLoadedRealms(config.getName(),authRealmName);
          CreateFileUser.handleAdminGroup(authRealmName,groups);
          String[] groups1=groups.toArray(new String[groups.size()]);
          try {
            fr.addUser(userName,password.toCharArray(),groups1);
          }
 catch (          BadRealmException br) {
            if (se != null && se.isDas()) {
              throw new BadRealmException(br);
            }
          }
          fr.persist();
          report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
 catch (        Exception e) {
          String localalizedErrorMsg=(e.getLocalizedMessage() == null) ? "String_Node_Str" : e.getLocalizedMessage();
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userName,authRealmName) + "String_Node_Str" + localalizedErrorMsg);
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setFailureCause(e);
        }
        return null;
      }
    }
,securityService);
  }
 catch (  Exception e) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",userName,authRealmName) + "String_Node_Str" + e.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(e);
  }
}