Program: 61231
Project: 61231
Buggy source:
private Map<String,Set<Attribute>> prepareAttributes(SyncopeUser user,TargetResource resource){
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str" + user + "String_Node_Str"+ resource+ "String_Node_Str"+ user.getAttributes());
  }
  String password=user.getPassword();
  List<SchemaMapping> mappings=resource.getMappings();
  Set<Attribute> attributes=new HashSet<Attribute>();
  Class castToBeApplied=null;
  String accountId=null;
  String field=null;
  Set objValues=null;
  String schemaName=null;
  SchemaType schemaType=null;
  UserAttribute userAttribute=null;
  SchemaValueType schemaValueType=null;
  List<UserAttributeValue> values=null;
  for (  SchemaMapping mapping : mappings) {
    try {
      field=mapping.getField();
      schemaName=mapping.getSchemaName();
      schemaType=mapping.getSchemaType();
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + schemaName + "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str");
      }
      AbstractSchema schema=null;
      try {
        schemaType.getSchemaType().asSubclass(AbstractSchema.class);
        schema=schemaDAO.find(schemaName,schemaType.getSchemaType());
      }
 catch (      ClassCastException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + schemaType.getClassName());
        }
      }
      if (schema != null) {
        schemaValueType=schema.getType();
        userAttribute=user.getAttribute(schemaName);
        values=userAttribute != null ? userAttribute.getAttributeValues() : Collections.EMPTY_LIST;
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + userAttribute + "String_Node_Str"+ schemaName+ "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str"+ values);
        }
      }
 else {
        schemaValueType=SchemaValueType.String;
        UserAttributeValue userAttributeValue=new UserAttributeValue();
        userAttributeValue.setStringValue(SchemaType.AccountId.equals(schemaType) ? user.getId().toString() : password);
        values=Collections.singletonList(userAttributeValue);
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + "String_Node_Str" + field + "String_Node_Str"+ mapping.isAccountid()+ "String_Node_Str"+ (mapping.isPassword() || schemaType.equals(SchemaType.Password))+ "String_Node_Str"+ mapping.isNullable()+ "String_Node_Str"+ schemaName+ "String_Node_Str"+ schemaType.toString()+ "String_Node_Str"+ schemaValueType.getClassName()+ "String_Node_Str"+ values);
      }
      objValues=new HashSet();
      for (      UserAttributeValue value : values) {
        castToBeApplied=Class.forName(schemaValueType.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()));
      }
      Object objValue=null;
      if (!objValues.isEmpty()) {
        objValue=objValues.iterator().next();
      }
      if (!mapping.isPassword() && !mapping.isAccountid()) {
        if (schema.isMultivalue()) {
          attributes.add(AttributeBuilder.build(field,objValues));
        }
 else {
          attributes.add(AttributeBuilder.build(field,castToBeApplied.cast(objValue)));
        }
      }
    }
 catch (    ClassNotFoundException e) {
      if (LOG.isWarnEnabled()) {
        LOG.warn("String_Node_Str" + schemaValueType.getClassName(),e);
      }
    }
catch (    Throwable t) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + schemaName + "String_Node_Str",t);
      }
    }
  }
  return Collections.singletonMap(accountId,attributes);
}

Fixed version (ground truth):
private Map<String,Set<Attribute>> prepareAttributes(SyncopeUser user,TargetResource resource){
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str" + user + "String_Node_Str"+ resource+ "String_Node_Str"+ user.getAttributes());
  }
  String password=user.getPassword();
  List<SchemaMapping> mappings=resource.getMappings();
  Set<Attribute> attributes=new HashSet<Attribute>();
  Class castToBeApplied=null;
  String accountId=null;
  String field=null;
  Set objValues=null;
  String schemaName=null;
  SchemaType schemaType=null;
  UserAttribute userAttribute=null;
  SchemaValueType schemaValueType=null;
  List<UserAttributeValue> values=null;
  for (  SchemaMapping mapping : mappings) {
    try {
      field=mapping.getField();
      schemaName=mapping.getSchemaName();
      schemaType=mapping.getSchemaType();
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + schemaName + "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str");
      }
      AbstractSchema schema=null;
      try {
        schemaType.getSchemaClass().asSubclass(AbstractSchema.class);
        schema=schemaDAO.find(schemaName,schemaType.getSchemaClass());
      }
 catch (      ClassCastException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + schemaType.getClassName());
        }
      }
      if (schema != null) {
        schemaValueType=schema.getType();
        userAttribute=user.getAttribute(schemaName);
        values=userAttribute != null ? userAttribute.getAttributeValues() : Collections.EMPTY_LIST;
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + userAttribute + "String_Node_Str"+ schemaName+ "String_Node_Str"+ schemaType.getClassName()+ "String_Node_Str"+ values);
        }
      }
 else {
        schemaValueType=SchemaValueType.String;
        UserAttributeValue userAttributeValue=new UserAttributeValue();
        userAttributeValue.setStringValue(SchemaType.AccountId.equals(schemaType) ? user.getId().toString() : password);
        values=Collections.singletonList(userAttributeValue);
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + "String_Node_Str" + field + "String_Node_Str"+ mapping.isAccountid()+ "String_Node_Str"+ (mapping.isPassword() || schemaType.equals(SchemaType.Password))+ "String_Node_Str"+ mapping.isNullable()+ "String_Node_Str"+ schemaName+ "String_Node_Str"+ schemaType.toString()+ "String_Node_Str"+ schemaValueType.getClassName()+ "String_Node_Str"+ values);
      }
      objValues=new HashSet();
      for (      UserAttributeValue value : values) {
        castToBeApplied=Class.forName(schemaValueType.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()));
      }
      Object objValue=null;
      if (!objValues.isEmpty()) {
        objValue=objValues.iterator().next();
      }
      if (!mapping.isPassword() && !mapping.isAccountid()) {
        if (schema.isMultivalue()) {
          attributes.add(AttributeBuilder.build(field,objValues));
        }
 else {
          attributes.add(AttributeBuilder.build(field,castToBeApplied.cast(objValue)));
        }
      }
    }
 catch (    ClassNotFoundException e) {
      if (LOG.isWarnEnabled()) {
        LOG.warn("String_Node_Str" + schemaValueType.getClassName(),e);
      }
    }
catch (    Throwable t) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("String_Node_Str" + schemaName + "String_Node_Str",t);
      }
    }
  }
  return Collections.singletonMap(accountId,attributes);
}