Program: 61351
Project: 61351
Buggy source:
/** 
 * Propagate provision/update the resource indicated.
 * @param user to be created.
 * @param resource to be provisioned.
 * @param merge specifies if it must be performed an update (true) or acreation (false).
 * @throws NoSuchBeanDefinitionException if the connector bean doesn'texist.
 * @throws IllegalStateException if propagation fails.
 */
private void propagate(SyncopeUser user,Resource resource,boolean merge) throws NoSuchBeanDefinitionException, IllegalStateException {
  ConnectorInstance connectorInstance=resource.getConnector();
  ConfigurableApplicationContext context=ApplicationContextManager.getApplicationContext();
  DefaultListableBeanFactory beanFactory=(DefaultListableBeanFactory)context.getBeanFactory();
  ConnectorFacade connector=(ConnectorFacade)beanFactory.getBean(connectorInstance.getId().toString());
  if (connector == null) {
    if (log.isErrorEnabled()) {
      log.error("String_Node_Str" + connectorInstance.getId().toString() + "String_Node_Str");
    }
    throw new NoSuchBeanDefinitionException("String_Node_Str");
  }
  Set<SchemaMapping> mappings=resource.getMappings();
  Set<Attribute> attrs=new HashSet<Attribute>();
  String accountId=null;
  String field=null;
  String password=user.getPassword();
  for (  SchemaMapping mapping : mappings) {
    field=mapping.getField();
    Object value=user.getAttribute(mapping.getUserSchema().getName());
    if (value != null && mapping.isAccountid()) {
      accountId=value.toString();
      attrs.add(new Name(accountId));
    }
    if (password != null && mapping.isPassword()) {
      attrs.add(AttributeBuilder.buildPassword(password.toCharArray()));
    }
    if (!mapping.isPassword() && !mapping.isAccountid()) {
      attrs.add(AttributeBuilder.build(field,value));
    }
  }
  Uid userUid=null;
  if (merge) {
    userUid=connector.update(ObjectClass.ACCOUNT,new Uid(accountId),attrs,null);
  }
 else {
    userUid=connector.create(ObjectClass.ACCOUNT,attrs,null);
  }
  if (userUid == null) {
    if (log.isErrorEnabled()) {
      log.error("String_Node_Str" + resource.getName());
    }
    throw new IllegalStateException("String_Node_Str");
  }
  if (log.isInfoEnabled()) {
    log.info("String_Node_Str" + userUid.getUidValue());
  }
}

Fixed version (ground truth):
/** 
 * Propagate provision/update the resource indicated.
 * @param user to be created.
 * @param resource to be provisioned.
 * @param merge specifies if it must be performed an update (true) or acreation (false).
 * @throws NoSuchBeanDefinitionException if the connector bean doesn'texist.
 * @throws IllegalStateException if propagation fails.
 */
private void propagate(SyncopeUser user,Resource resource,boolean merge) throws NoSuchBeanDefinitionException, IllegalStateException {
  ConnectorInstance connectorInstance=resource.getConnector();
  ConnectorFacade connector=getConnectorFacade(connectorInstance.getId().toString());
  if (connector == null) {
    if (log.isErrorEnabled()) {
      log.error("String_Node_Str" + connectorInstance.getId().toString() + "String_Node_Str");
    }
    throw new NoSuchBeanDefinitionException("String_Node_Str");
  }
  Set<SchemaMapping> mappings=resource.getMappings();
  Set<Attribute> attrs=new HashSet<Attribute>();
  Class castToBeApplied=null;
  SchemaType type=null;
  String accountId=null;
  String field=null;
  UserAttribute userAttribute=null;
  String schema=null;
  Set<UserAttributeValue> values=null;
  String password=user.getPassword();
  Set objValues=new HashSet();
  for (  SchemaMapping mapping : mappings) {
    field=mapping.getField();
    schema=mapping.getUserSchema().getName();
    userAttribute=user.getAttribute(schema);
    values=null;
    try {
      type=mapping.getUserSchema().getType();
      castToBeApplied=Class.forName(type.getClassName());
    }
 catch (    ClassNotFoundException e) {
      castToBeApplied=String.class;
    }
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + "String_Node_Str" + field + "String_Node_Str"+ schema+ "String_Node_Str"+ type.getClassName());
    }
    if (userAttribute != null) {
      values=(Set<UserAttributeValue>)userAttribute.getAttributeValues();
      for (      UserAttributeValue value : values) {
        objValues.add(value.getValue());
      }
    }
    if (!objValues.isEmpty() && mapping.isAccountid()) {
      accountId=objValues.iterator().next().toString();
      attrs.add(new Name(accountId));
    }
    if (password != null && mapping.isPassword()) {
      attrs.add(AttributeBuilder.buildPassword(password.toCharArray()));
    }
    if (!mapping.isPassword() && !mapping.isAccountid() && !objValues.isEmpty()) {
      if (mapping.getUserSchema().isMultivalue()) {
        attrs.add(AttributeBuilder.build(field,objValues));
      }
 else {
        attrs.add(AttributeBuilder.build(field,castToBeApplied.cast(objValues.iterator().next())));
      }
    }
  }
  Uid userUid=null;
  if (merge) {
    userUid=connector.update(ObjectClass.ACCOUNT,new Uid(accountId),attrs,null);
  }
 else {
    userUid=connector.create(ObjectClass.ACCOUNT,attrs,null);
  }
  if (userUid == null) {
    if (log.isErrorEnabled()) {
      log.error("String_Node_Str" + resource.getName());
    }
    throw new IllegalStateException("String_Node_Str");
  }
  if (log.isInfoEnabled()) {
    log.info("String_Node_Str" + userUid.getUidValue());
  }
}