Program: 30115
Project: 30115
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();
  if (authRealmName == null)   authRealmName=securityService.getDefaultRealm();
  AuthRealm fileAuthRealm=null;
  for (  AuthRealm authRealm : securityService.getAuthRealm()) {
    if (authRealm.getName().equals(authRealmName))     fileAuthRealm=authRealm;
  }
  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();
  }
  if (keyFile == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  boolean exists=(new File(keyFile)).exists();
  if (!exists) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{keyFile,authRealmName}));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String password=userpassword;
  if (password == null && groups == 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;
  }
  FileRealm fr=null;
  try {
    realmsManager.createRealms(config);
    fr=(FileRealm)realmsManager.getFromLoadedRealms(config.getName(),authRealmName);
    if (fr == null) {
      throw new NoSuchRealmException(authRealmName);
    }
  }
 catch (  NoSuchRealmException e) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName) + "String_Node_Str" + e.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(e);
    return;
  }
  try {
    CreateFileUser.handleAdminGroup(authRealmName,groups);
    String[] groups1=(groups == null) ? null : groups.toArray(new String[groups.size()]);
    fr.updateUser(userName,userName,password,groups1);
    fr.writeKeyFile(keyFile);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
  }
 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();
  if (authRealmName == null)   authRealmName=securityService.getDefaultRealm();
  AuthRealm fileAuthRealm=null;
  for (  AuthRealm authRealm : securityService.getAuthRealm()) {
    if (authRealm.getName().equals(authRealmName))     fileAuthRealm=authRealm;
  }
  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();
  }
  if (keyFile == null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  boolean exists=(new File(keyFile)).exists();
  if (!exists) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{keyFile,authRealmName}));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return;
  }
  String password=userpassword;
  if (password == null && groups == 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;
  }
  if (password != null) {
    secureAdmin=domain.getSecureAdmin();
    if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (adminService.getAuthRealmName().equals(authRealmName))) {
      if ((password.isEmpty())) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
  }
  FileRealm fr=null;
  try {
    realmsManager.createRealms(config);
    fr=(FileRealm)realmsManager.getFromLoadedRealms(config.getName(),authRealmName);
    if (fr == null) {
      throw new NoSuchRealmException(authRealmName);
    }
  }
 catch (  NoSuchRealmException e) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",authRealmName) + "String_Node_Str" + e.getLocalizedMessage());
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    report.setFailureCause(e);
    return;
  }
  try {
    CreateFileUser.handleAdminGroup(authRealmName,groups);
    String[] groups1=(groups == null) ? null : groups.toArray(new String[groups.size()]);
    fr.updateUser(userName,userName,password,groups1);
    fr.writeKeyFile(keyFile);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
  }
 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);
  }
}