Program: 60525
Project: 60525
Buggy source:
/** 
 * Prepare an attribute to be sent to a connector instance.
 * @param resource target resource
 * @param < T > user / role
 * @param mapItem mapping item for the given attribute
 * @param subject given user
 * @param password clear-text password
 * @param passwordGenerator password generator
 * @param vAttrsToBeRemoved virtual attributes to be removed
 * @param vAttrsToBeUpdated virtual attributes to be added
 * @return account link + prepared attribute
 */
@SuppressWarnings("String_Node_Str") private static <T extends AbstractAttributable>Map.Entry<String,Attribute> prepareAttribute(final ExternalResource resource,final AbstractMappingItem mapItem,final T subject,final String password,final PasswordGenerator passwordGenerator,final Set<String> vAttrsToBeRemoved,final Map<String,AttributeMod> vAttrsToBeUpdated,final Set<String> membVAttrsToBeRemoved,final Map<String,AttributeMod> membVAttrsToBeUpdated){
  final List<AbstractAttributable> attributables=new ArrayList<AbstractAttributable>();
  final ConfigurableApplicationContext context=ApplicationContextProvider.getApplicationContext();
  final ConnObjectUtil connObjectUtil=context.getBean(ConnObjectUtil.class);
switch (mapItem.getIntMappingType().getAttributableType()) {
case USER:
    if (subject instanceof SyncopeUser) {
      attributables.add(subject);
    }
  break;
case ROLE:
if (subject instanceof SyncopeUser) {
  for (  SyncopeRole role : ((SyncopeUser)subject).getRoles()) {
    connObjectUtil.retrieveVirAttrValues(role,AttributableUtil.getInstance(role));
    attributables.add(role);
  }
}
if (subject instanceof SyncopeRole) {
attributables.add(subject);
}
break;
case MEMBERSHIP:
if (subject instanceof SyncopeUser) {
attributables.addAll(((SyncopeUser)subject).getMemberships());
}
break;
default :
}
List<AbstractAttrValue> values=getIntValues(resource,mapItem,attributables,vAttrsToBeRemoved,vAttrsToBeUpdated,membVAttrsToBeRemoved,membVAttrsToBeUpdated);
AbstractNormalSchema schema=null;
boolean readOnlyVirSchema=false;
AttributeSchemaType schemaType;
final Map.Entry<String,Attribute> result;
switch (mapItem.getIntMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
final SchemaDAO schemaDAO=context.getBean(SchemaDAO.class);
schema=schemaDAO.find(mapItem.getIntAttrName(),MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
schemaType=schema == null ? AttributeSchemaType.String : schema.getType();
break;
case UserVirtualSchema:
case RoleVirtualSchema:
case MembershipVirtualSchema:
VirSchemaDAO virSchemaDAO=context.getBean(VirSchemaDAO.class);
AbstractVirSchema virSchema=virSchemaDAO.find(mapItem.getIntAttrName(),MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
readOnlyVirSchema=(virSchema != null && virSchema.isReadonly());
schemaType=AttributeSchemaType.String;
break;
default :
schemaType=AttributeSchemaType.String;
}
final String extAttrName=mapItem.getExtAttrName();
LOG.debug("String_Node_Str" + "String_Node_Str" + extAttrName + "String_Node_Str"+ mapItem.isAccountid()+ "String_Node_Str"+ (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)+ "String_Node_Str"+ mapItem.getMandatoryCondition()+ "String_Node_Str"+ mapItem.getIntAttrName()+ "String_Node_Str"+ mapItem.getIntMappingType().toString()+ "String_Node_Str"+ schemaType.getType().getName()+ "String_Node_Str"+ values);
if (readOnlyVirSchema) {
result=null;
}
 else {
final List<Object> objValues=new ArrayList<Object>();
for (AbstractAttrValue value : values) {
if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
objValues.add(value.getValue());
}
 else {
objValues.add(value.getValueAsString());
}
}
if (mapItem.isAccountid()) {
result=new AbstractMap.SimpleEntry<String,Attribute>(objValues.iterator().next().toString(),null);
}
 else if (mapItem.isPassword() && subject instanceof SyncopeUser) {
String passwordAttrValue=password;
if (StringUtils.isBlank(passwordAttrValue)) {
SyncopeUser user=(SyncopeUser)subject;
if (user.canDecodePassword()) {
try {
passwordAttrValue=ENCRYPTOR.decode(user.getPassword(),user.getCipherAlgorithm());
}
 catch (Exception e) {
LOG.error("String_Node_Str",user,e);
}
}
 else if (resource.isRandomPwdIfNotProvided()) {
try {
passwordAttrValue=passwordGenerator.generate(user);
}
 catch (InvalidPasswordPolicySpecException e) {
LOG.error("String_Node_Str",user,e);
}
}
}
if (passwordAttrValue == null) {
result=null;
}
 else {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
}
}
 else {
if ((schema != null && schema.isMultivalue()) || AttributableUtil.getInstance(subject).getType() != mapItem.getIntMappingType().getAttributableType()) {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,AttributeBuilder.build(extAttrName,objValues));
}
 else {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,objValues.isEmpty() ? AttributeBuilder.build(extAttrName) : AttributeBuilder.build(extAttrName,objValues.iterator().next()));
}
}
}
return result;
}

Fixed version (ground truth):
/** 
 * Prepare an attribute to be sent to a connector instance.
 * @param resource target resource
 * @param < T > user / role
 * @param mapItem mapping item for the given attribute
 * @param subject given user
 * @param password clear-text password
 * @param passwordGenerator password generator
 * @param vAttrsToBeRemoved virtual attributes to be removed
 * @param vAttrsToBeUpdated virtual attributes to be added
 * @return account link + prepared attribute
 */
@SuppressWarnings("String_Node_Str") private static <T extends AbstractAttributable>Map.Entry<String,Attribute> prepareAttribute(final ExternalResource resource,final AbstractMappingItem mapItem,final T subject,final String password,final PasswordGenerator passwordGenerator,final Set<String> vAttrsToBeRemoved,final Map<String,AttributeMod> vAttrsToBeUpdated,final Set<String> membVAttrsToBeRemoved,final Map<String,AttributeMod> membVAttrsToBeUpdated){
  final List<AbstractAttributable> attributables=new ArrayList<AbstractAttributable>();
  final ConfigurableApplicationContext context=ApplicationContextProvider.getApplicationContext();
  final ConnObjectUtil connObjectUtil=context.getBean(ConnObjectUtil.class);
switch (mapItem.getIntMappingType().getAttributableType()) {
case USER:
    if (subject instanceof SyncopeUser) {
      attributables.add(subject);
    }
  break;
case ROLE:
if (subject instanceof SyncopeUser) {
  for (  SyncopeRole role : ((SyncopeUser)subject).getRoles()) {
    connObjectUtil.retrieveVirAttrValues(role,AttributableUtil.getInstance(role));
    attributables.add(role);
  }
}
if (subject instanceof SyncopeRole) {
attributables.add(subject);
}
break;
case MEMBERSHIP:
if (subject instanceof SyncopeUser) {
attributables.addAll(((SyncopeUser)subject).getMemberships());
}
break;
default :
}
List<AbstractAttrValue> values=getIntValues(resource,mapItem,attributables,vAttrsToBeRemoved,vAttrsToBeUpdated,membVAttrsToBeRemoved,membVAttrsToBeUpdated);
AbstractSchema schema=null;
boolean readOnlyVirSchema=false;
AttributeSchemaType schemaType;
final Map.Entry<String,Attribute> result;
switch (mapItem.getIntMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
final SchemaDAO schemaDAO=context.getBean(SchemaDAO.class);
schema=schemaDAO.find(mapItem.getIntAttrName(),MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
schemaType=schema == null ? AttributeSchemaType.String : schema.getType();
break;
case UserVirtualSchema:
case RoleVirtualSchema:
case MembershipVirtualSchema:
VirSchemaDAO virSchemaDAO=context.getBean(VirSchemaDAO.class);
schema=virSchemaDAO.find(mapItem.getIntAttrName(),MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
readOnlyVirSchema=(schema != null && schema.isReadonly());
schemaType=AttributeSchemaType.String;
break;
default :
schemaType=AttributeSchemaType.String;
}
final String extAttrName=mapItem.getExtAttrName();
LOG.debug("String_Node_Str" + "String_Node_Str" + extAttrName + "String_Node_Str"+ mapItem.isAccountid()+ "String_Node_Str"+ (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)+ "String_Node_Str"+ mapItem.getMandatoryCondition()+ "String_Node_Str"+ mapItem.getIntAttrName()+ "String_Node_Str"+ mapItem.getIntMappingType().toString()+ "String_Node_Str"+ schemaType.getType().getName()+ "String_Node_Str"+ values);
if (readOnlyVirSchema) {
result=null;
}
 else {
final List<Object> objValues=new ArrayList<Object>();
for (AbstractAttrValue value : values) {
if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
objValues.add(value.getValue());
}
 else {
objValues.add(value.getValueAsString());
}
}
if (mapItem.isAccountid()) {
result=new AbstractMap.SimpleEntry<String,Attribute>(objValues.iterator().next().toString(),null);
}
 else if (mapItem.isPassword() && subject instanceof SyncopeUser) {
String passwordAttrValue=password;
if (StringUtils.isBlank(passwordAttrValue)) {
SyncopeUser user=(SyncopeUser)subject;
if (user.canDecodePassword()) {
try {
passwordAttrValue=ENCRYPTOR.decode(user.getPassword(),user.getCipherAlgorithm());
}
 catch (Exception e) {
LOG.error("String_Node_Str",user,e);
}
}
 else if (resource.isRandomPwdIfNotProvided()) {
try {
passwordAttrValue=passwordGenerator.generate(user);
}
 catch (InvalidPasswordPolicySpecException e) {
LOG.error("String_Node_Str",user,e);
}
}
}
if (passwordAttrValue == null) {
result=null;
}
 else {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
}
}
 else {
if ((schema != null && schema.isMultivalue()) || AttributableUtil.getInstance(subject).getType() != mapItem.getIntMappingType().getAttributableType()) {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,AttributeBuilder.build(extAttrName,objValues));
}
 else {
result=new AbstractMap.SimpleEntry<String,Attribute>(null,objValues.isEmpty() ? AttributeBuilder.build(extAttrName) : AttributeBuilder.build(extAttrName,objValues.iterator().next()));
}
}
}
return result;
}