Program: 61347
Project: 61347
Buggy source:
public SyncopeUser createSyncopeUser(UserTO userTO) throws SyncopeClientCompositeErrorException {
  SyncopeClientCompositeErrorException compositeErrorException=new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
  SyncopeClientException invalidPassword=new SyncopeClientException(SyncopeClientExceptionType.InvalidPassword);
  SyncopeClientException invalidSchemas=new SyncopeClientException(SyncopeClientExceptionType.InvalidSchemas);
  SyncopeClientException requiredValuesMissing=new SyncopeClientException(SyncopeClientExceptionType.RequiredValuesMissing);
  SyncopeClientException invalidValues=new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);
  SyncopeClientException invalidUniques=new SyncopeClientException(SyncopeClientExceptionType.InvalidUniques);
  SyncopeClientException invalidDerivedSchemas=new SyncopeClientException(SyncopeClientExceptionType.InvalidDerivedSchemas);
  SyncopeClientException invalidRoles=new SyncopeClientException(SyncopeClientExceptionType.InvalidRoles);
  SyncopeClientException invalidResources=new SyncopeClientException(SyncopeClientExceptionType.InvalidResources);
  SyncopeUser syncopeUser=new SyncopeUser();
  BeanUtils.copyProperties(userTO,syncopeUser,(String[])ArrayUtils.add(ignoreProperties,"String_Node_Str"));
  if (userTO.getPassword() == null || userTO.getPassword().length() == 0) {
    log.error("String_Node_Str");
    invalidPassword.addElement("String_Node_Str");
    compositeErrorException.addException(invalidPassword);
  }
 else {
    syncopeUser.setPassword(userTO.getPassword());
  }
  UserSchema schema=null;
  UserAttribute attribute=null;
  Set<String> valuesProvided=null;
  UserAttributeValue attributeValue=null;
  for (  AttributeTO attributeTO : userTO.getAttributes()) {
    schema=schemaDAO.find(attributeTO.getSchema(),UserSchema.class);
    if (schema == null) {
      invalidSchemas.addElement(attributeTO.getSchema());
    }
 else {
      attribute=new UserAttribute();
      attribute.setSchema(schema);
      attribute.setOwner(syncopeUser);
      valuesProvided=schema.isMultivalue() ? attributeTO.getValues() : (attributeTO.getValues().isEmpty() ? Collections.EMPTY_SET : Collections.singleton(attributeTO.getValues().iterator().next()));
      for (      String value : valuesProvided) {
        attributeValue=new UserAttributeValue();
        try {
          attributeValue=attribute.addValue(value,attributeValue);
        }
 catch (        ValidationException e) {
          log.error("String_Node_Str" + schema.getName() + "String_Node_Str"+ value,e);
          invalidValues.addElement(schema.getName());
        }
        if (schema.isUniquevalue() && attributeValueDAO.existingAttributeValue(attributeValue)) {
          log.error("String_Node_Str" + schema.getName() + "String_Node_Str"+ attributeValue.getValueAsString());
          invalidUniques.addElement(schema.getName());
          attribute.setAttributeValues(Collections.EMPTY_SET);
        }
      }
      if (!attribute.getAttributeValues().isEmpty()) {
        syncopeUser.addAttribute(attribute);
      }
    }
  }
  UserDerivedSchema derivedSchema=null;
  UserDerivedAttribute derivedAttribute=null;
  for (  AttributeTO attributeTO : userTO.getDerivedAttributes()) {
    derivedSchema=derivedSchemaDAO.find(attributeTO.getSchema(),UserDerivedSchema.class);
    if (derivedSchema == null) {
      invalidDerivedSchemas.addElement(attributeTO.getSchema());
    }
 else {
      derivedAttribute=new UserDerivedAttribute();
      derivedAttribute.setDerivedSchema(derivedSchema);
      derivedAttribute.setOwner(syncopeUser);
      syncopeUser.addDerivedAttribute(derivedAttribute);
    }
  }
  List<UserSchema> allUserSchemas=schemaDAO.findAll(UserSchema.class);
  for (  UserSchema userSchema : allUserSchemas) {
    if (syncopeUser.getAttribute(userSchema.getName()) == null && userSchema.isMandatory()) {
      log.error("String_Node_Str" + userSchema.getName() + "String_Node_Str");
      requiredValuesMissing.addElement(userSchema.getName());
    }
  }
  SyncopeRole role=null;
  for (  Long roleId : userTO.getRoles()) {
    role=syncopeRoleDAO.find(roleId);
    if (role == null) {
      invalidRoles.addElement(String.valueOf(roleId));
    }
 else {
      syncopeUser.addRole(role);
    }
  }
  Resource resource=null;
  for (  String resourceName : userTO.getResources()) {
    resource=resourceDAO.find(resourceName);
    if (resource == null) {
      invalidResources.addElement(resourceName);
    }
 else {
      syncopeUser.addResource(resource);
    }
  }
  if (!invalidSchemas.getElements().isEmpty()) {
    compositeErrorException.addException(invalidSchemas);
  }
  if (!requiredValuesMissing.getElements().isEmpty()) {
    compositeErrorException.addException(requiredValuesMissing);
  }
  if (!invalidValues.getElements().isEmpty()) {
    compositeErrorException.addException(invalidValues);
  }
  if (!invalidUniques.getElements().isEmpty()) {
    compositeErrorException.addException(invalidUniques);
  }
  if (!invalidDerivedSchemas.getElements().isEmpty()) {
    compositeErrorException.addException(invalidDerivedSchemas);
  }
  if (!invalidRoles.getElements().isEmpty()) {
    compositeErrorException.addException(invalidRoles);
  }
  if (!invalidResources.getElements().isEmpty()) {
    compositeErrorException.addException(invalidResources);
  }
  if (compositeErrorException.hasExceptions()) {
    throw compositeErrorException;
  }
  return syncopeUser;
}

Fixed version (ground truth):
public SyncopeUser createSyncopeUser(UserTO userTO) throws SyncopeClientCompositeErrorException {
  SyncopeClientCompositeErrorException compositeErrorException=new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
  SyncopeClientException invalidPassword=new SyncopeClientException(SyncopeClientExceptionType.InvalidPassword);
  SyncopeClientException requiredValuesMissing=new SyncopeClientException(SyncopeClientExceptionType.RequiredValuesMissing);
  SyncopeClientException invalidValues=new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);
  SyncopeClientException invalidUniques=new SyncopeClientException(SyncopeClientExceptionType.InvalidUniques);
  SyncopeClientException invalidDerivedSchemas=new SyncopeClientException(SyncopeClientExceptionType.InvalidDerivedSchemas);
  SyncopeClientException invalidRoles=new SyncopeClientException(SyncopeClientExceptionType.InvalidRoles);
  SyncopeClientException invalidResources=new SyncopeClientException(SyncopeClientExceptionType.InvalidResources);
  SyncopeUser syncopeUser=new SyncopeUser();
  BeanUtils.copyProperties(userTO,syncopeUser,(String[])ArrayUtils.add(ignoreProperties,"String_Node_Str"));
  if (userTO.getPassword() == null || userTO.getPassword().length() == 0) {
    log.error("String_Node_Str");
    invalidPassword.addElement("String_Node_Str");
    compositeErrorException.addException(invalidPassword);
  }
 else {
    syncopeUser.setPassword(userTO.getPassword());
  }
  UserSchema schema=null;
  UserAttribute attribute=null;
  Set<String> valuesProvided=null;
  UserAttributeValue attributeValue=null;
  for (  AttributeTO attributeTO : userTO.getAttributes()) {
    schema=schemaDAO.find(attributeTO.getSchema(),UserSchema.class);
    if (schema != null) {
      attribute=new UserAttribute();
      attribute.setSchema(schema);
      attribute.setOwner(syncopeUser);
      valuesProvided=schema.isMultivalue() ? attributeTO.getValues() : (attributeTO.getValues().isEmpty() ? Collections.EMPTY_SET : Collections.singleton(attributeTO.getValues().iterator().next()));
      for (      String value : valuesProvided) {
        attributeValue=new UserAttributeValue();
        try {
          attributeValue=attribute.addValue(value,attributeValue);
        }
 catch (        ValidationException e) {
          log.error("String_Node_Str" + schema.getName() + "String_Node_Str"+ value,e);
          invalidValues.addElement(schema.getName());
        }
        if (schema.isUniquevalue() && attributeValueDAO.existingAttributeValue(attributeValue)) {
          log.error("String_Node_Str" + schema.getName() + "String_Node_Str"+ attributeValue.getValueAsString());
          invalidUniques.addElement(schema.getName());
          attribute.setAttributeValues(Collections.EMPTY_SET);
        }
      }
      if (!attribute.getAttributeValues().isEmpty()) {
        syncopeUser.addAttribute(attribute);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + attributeTO.getSchema());
      }
    }
  }
  UserDerivedSchema derivedSchema=null;
  UserDerivedAttribute derivedAttribute=null;
  for (  AttributeTO attributeTO : userTO.getDerivedAttributes()) {
    derivedSchema=derivedSchemaDAO.find(attributeTO.getSchema(),UserDerivedSchema.class);
    if (derivedSchema == null) {
      invalidDerivedSchemas.addElement(attributeTO.getSchema());
    }
 else {
      derivedAttribute=new UserDerivedAttribute();
      derivedAttribute.setDerivedSchema(derivedSchema);
      derivedAttribute.setOwner(syncopeUser);
      syncopeUser.addDerivedAttribute(derivedAttribute);
    }
  }
  List<UserSchema> allUserSchemas=schemaDAO.findAll(UserSchema.class);
  for (  UserSchema userSchema : allUserSchemas) {
    if (syncopeUser.getAttribute(userSchema.getName()) == null && userSchema.isMandatory()) {
      log.error("String_Node_Str" + userSchema.getName() + "String_Node_Str");
      requiredValuesMissing.addElement(userSchema.getName());
    }
  }
  SyncopeRole role=null;
  for (  Long roleId : userTO.getRoles()) {
    role=syncopeRoleDAO.find(roleId);
    if (role == null) {
      invalidRoles.addElement(String.valueOf(roleId));
    }
 else {
      syncopeUser.addRole(role);
    }
  }
  Resource resource=null;
  for (  String resourceName : userTO.getResources()) {
    resource=resourceDAO.find(resourceName);
    if (resource == null) {
      invalidResources.addElement(resourceName);
    }
 else {
      syncopeUser.addResource(resource);
    }
  }
  if (!requiredValuesMissing.getElements().isEmpty()) {
    compositeErrorException.addException(requiredValuesMissing);
  }
  if (!invalidValues.getElements().isEmpty()) {
    compositeErrorException.addException(invalidValues);
  }
  if (!invalidUniques.getElements().isEmpty()) {
    compositeErrorException.addException(invalidUniques);
  }
  if (!invalidDerivedSchemas.getElements().isEmpty()) {
    compositeErrorException.addException(invalidDerivedSchemas);
  }
  if (!invalidRoles.getElements().isEmpty()) {
    compositeErrorException.addException(invalidRoles);
  }
  if (!invalidResources.getElements().isEmpty()) {
    compositeErrorException.addException(invalidResources);
  }
  if (compositeErrorException.hasExceptions()) {
    throw compositeErrorException;
  }
  return syncopeUser;
}