Program: 61130
Project: 61130
Buggy source:
private Map<String,Set<Attribute>> prepareAttributes(SyncopeUser user,String password,TargetResource resource){
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str" + user + "String_Node_Str"+ resource+ "String_Node_Str"+ user.getAttributes());
  }
  Set<Attribute> attributes=new HashSet<Attribute>();
  Class castToBeApplied;
  String accountId=null;
  Set objValues;
  UAttr attr;
  AbstractSchema schema;
  SchemaType schemaType=null;
  List<AbstractAttrValue> values;
  for (  SchemaMapping mapping : resource.getMappings()) {
    LOG.debug("String_Node_Str",mapping.getSourceAttrName());
    try {
switch (mapping.getSourceMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
        schema=schemaDAO.find(mapping.getSourceAttrName(),getSourceMappingTypeClass(mapping.getSourceMappingType()));
      schemaType=schema.getType();
    attr=user.getAttribute(mapping.getSourceAttrName());
  values=attr != null ? (schema.isUniqueConstraint() ? Collections.singletonList(attr.getUniqueValue()) : attr.getValues()) : Collections.EMPTY_LIST;
if (LOG.isDebugEnabled()) {
  LOG.debug("String_Node_Str" + attr + "String_Node_Str"+ mapping.getSourceAttrName()+ "String_Node_Str"+ mapping.getSourceMappingType()+ "String_Node_Str"+ values);
}
break;
case SyncopeUserId:
case Password:
schema=null;
schemaType=SchemaType.String;
AbstractAttrValue uAttrValue=new UAttrValue();
if (SourceMappingType.SyncopeUserId == mapping.getSourceMappingType()) {
uAttrValue.setStringValue(user.getId().toString());
}
if (SourceMappingType.Password == mapping.getSourceMappingType() && password != null) {
uAttrValue.setStringValue(password);
}
values=Collections.singletonList(uAttrValue);
break;
default :
schema=null;
values=null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("String_Node_Str" + "String_Node_Str" + mapping.getDestAttrName() + "String_Node_Str"+ mapping.isAccountid()+ "String_Node_Str"+ (mapping.isPassword() || mapping.getSourceMappingType().equals(SourceMappingType.Password))+ "String_Node_Str"+ mapping.getMandatoryCondition()+ "String_Node_Str"+ mapping.getSourceAttrName()+ "String_Node_Str"+ mapping.getSourceMappingType().toString()+ "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str"+ values);
}
objValues=new HashSet();
for (AbstractAttrValue value : values) {
castToBeApplied=Class.forName(schemaType.getClassName());
if (!FrameworkUtil.isSupportedAttributeType(castToBeApplied)) {
castToBeApplied=String.class;
objValues.add(value.getValueAsString());
}
 else {
objValues.add(value.getValue());
}
}
if (mapping.isAccountid()) {
accountId=objValues.iterator().next().toString();
attributes.add(new Name(accountId));
}
if (mapping.isPassword()) {
attributes.add(AttributeBuilder.buildPassword(objValues.iterator().next().toString().toCharArray()));
}
if (!mapping.isPassword() && !mapping.isAccountid()) {
if (schema != null && schema.isMultivalue()) {
attributes.add(AttributeBuilder.build(mapping.getDestAttrName(),objValues));
}
 else {
attributes.add(objValues.isEmpty() ? AttributeBuilder.build(mapping.getDestAttrName()) : AttributeBuilder.build(mapping.getDestAttrName(),objValues.iterator().next()));
}
}
}
 catch (Throwable t) {
LOG.debug("String_Node_Str",mapping.getSourceAttrName(),t);
}
}
return Collections.singletonMap(accountId,attributes);
}

Fixed version (ground truth):
private Map<String,Set<Attribute>> prepareAttributes(SyncopeUser user,String password,TargetResource resource){
  LOG.debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str",new Object[]{user,resource,user.getAttributes()});
  Set<Attribute> attributes=new HashSet<Attribute>();
  Class castToBeApplied;
  String accountId=null;
  Set objValues;
  UAttr attr;
  AbstractSchema schema;
  SchemaType schemaType=null;
  List<AbstractAttrValue> values;
  for (  SchemaMapping mapping : resource.getMappings()) {
    LOG.debug("String_Node_Str",mapping.getSourceAttrName());
    try {
switch (mapping.getSourceMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
        schema=schemaDAO.find(mapping.getSourceAttrName(),getSourceMappingTypeClass(mapping.getSourceMappingType()));
      schemaType=schema.getType();
    attr=user.getAttribute(mapping.getSourceAttrName());
  values=attr != null ? (schema.isUniqueConstraint() ? Collections.singletonList(attr.getUniqueValue()) : attr.getValues()) : Collections.EMPTY_LIST;
LOG.debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",new Object[]{attr,mapping.getSourceAttrName(),mapping.getSourceMappingType(),values});
break;
case SyncopeUserId:
case Password:
schema=null;
schemaType=SchemaType.String;
AbstractAttrValue uAttrValue=new UAttrValue();
if (SourceMappingType.SyncopeUserId == mapping.getSourceMappingType()) {
uAttrValue.setStringValue(user.getId().toString());
}
if (SourceMappingType.Password == mapping.getSourceMappingType() && password != null) {
uAttrValue.setStringValue(password);
}
values=Collections.singletonList(uAttrValue);
break;
default :
schema=null;
values=null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("String_Node_Str" + "String_Node_Str" + mapping.getDestAttrName() + "String_Node_Str"+ mapping.isAccountid()+ "String_Node_Str"+ (mapping.isPassword() || mapping.getSourceMappingType().equals(SourceMappingType.Password))+ "String_Node_Str"+ mapping.getMandatoryCondition()+ "String_Node_Str"+ mapping.getSourceAttrName()+ "String_Node_Str"+ mapping.getSourceMappingType().toString()+ "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str"+ values);
}
objValues=new HashSet();
for (AbstractAttrValue value : values) {
castToBeApplied=Class.forName(schemaType.getClassName());
if (!FrameworkUtil.isSupportedAttributeType(castToBeApplied)) {
castToBeApplied=String.class;
objValues.add(value.getValueAsString());
}
 else {
objValues.add(value.getValue());
}
}
if (mapping.isAccountid()) {
accountId=objValues.iterator().next().toString();
attributes.add(new Name(accountId));
}
if (mapping.isPassword()) {
attributes.add(AttributeBuilder.buildPassword(objValues.iterator().next().toString().toCharArray()));
}
if (!mapping.isPassword() && !mapping.isAccountid()) {
if (schema != null && schema.isMultivalue()) {
attributes.add(AttributeBuilder.build(mapping.getDestAttrName(),objValues));
}
 else {
attributes.add(objValues.isEmpty() ? AttributeBuilder.build(mapping.getDestAttrName()) : AttributeBuilder.build(mapping.getDestAttrName(),objValues.iterator().next()));
}
}
}
 catch (Throwable t) {
LOG.debug("String_Node_Str",mapping.getSourceAttrName(),t);
}
}
return Collections.singletonMap(accountId,attributes);
}