Program: 61294
Project: 61294
Buggy source:
public SyncopeUser createSyncopeUser(UserTO userTO) throws SyncopeClientCompositeErrorException, NotFoundException {
  SyncopeClientCompositeErrorException scce=new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
  SyncopeUser syncopeUser=null;
  if (userTO.getId() == 0) {
    syncopeUser=new SyncopeUser();
  }
 else {
    syncopeUser=syncopeUserDAO.find(userTO.getId());
    if (syncopeUser == null) {
      log.error("String_Node_Str" + userTO.getId() + "String_Node_Str");
      throw new NotFoundException(String.valueOf(userTO.getId()));
    }
  }
  SyncopeClientException invalidPassword=new SyncopeClientException(SyncopeClientExceptionType.InvalidPassword);
  if (userTO.getPassword() == null || userTO.getPassword().length() == 0) {
    log.error("String_Node_Str");
    invalidPassword.addElement("String_Node_Str");
  }
 else {
    syncopeUser.setPassword(userTO.getPassword());
  }
  if (!invalidPassword.getElements().isEmpty()) {
    scce.addException(invalidPassword);
  }
  syncopeUser=(SyncopeUser)fill(syncopeUser,userTO,AttributableUtil.USER,scce);
  SyncopeRole role=null;
  for (  MembershipTO membershipTO : userTO.getMemberships()) {
    role=syncopeRoleDAO.find(membershipTO.getRole());
    if (role == null) {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + membershipTO.getRole());
      }
    }
 else {
      Membership membership=new Membership();
      membership.setSyncopeRole(role);
      membership.setSyncopeUser(syncopeUser);
      membership=(Membership)fill(membership,membershipTO,AttributableUtil.MEMBERSHIP,scce);
      syncopeUser.addMembership(membership);
    }
  }
  return syncopeUser;
}

Fixed version (ground truth):
public SyncopeUser createSyncopeUser(UserTO userTO) throws SyncopeClientCompositeErrorException, NotFoundException {
  SyncopeClientCompositeErrorException scce=new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
  Set<Long> formerMembershipIds=Collections.EMPTY_SET;
  SyncopeUser syncopeUser=null;
  if (userTO.getId() == 0) {
    syncopeUser=new SyncopeUser();
  }
 else {
    syncopeUser=syncopeUserDAO.find(userTO.getId());
    if (syncopeUser == null) {
      log.error("String_Node_Str" + userTO.getId() + "String_Node_Str");
      throw new NotFoundException(String.valueOf(userTO.getId()));
    }
    formerMembershipIds=new HashSet<Long>();
    for (    Membership membership : syncopeUser.getMemberships()) {
      formerMembershipIds.add(membership.getId());
    }
  }
  SyncopeClientException invalidPassword=new SyncopeClientException(SyncopeClientExceptionType.InvalidPassword);
  if (userTO.getPassword() == null || userTO.getPassword().length() == 0) {
    log.error("String_Node_Str");
    invalidPassword.addElement("String_Node_Str");
  }
 else {
    syncopeUser.setPassword(userTO.getPassword());
  }
  if (!invalidPassword.getElements().isEmpty()) {
    scce.addException(invalidPassword);
  }
  syncopeUser=(SyncopeUser)fill(syncopeUser,userTO,AttributableUtil.USER,scce);
  SyncopeRole role=null;
  for (  MembershipTO membershipTO : userTO.getMemberships()) {
    role=syncopeRoleDAO.find(membershipTO.getRole());
    if (role == null) {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + membershipTO.getRole());
      }
    }
 else {
      Membership membership=null;
      if (syncopeUser.getId() != null) {
        membership=membershipDAO.find(syncopeUser,role);
      }
      if (membership == null) {
        membership=new Membership();
        membership.setSyncopeRole(role);
        membership.setSyncopeUser(syncopeUser);
        syncopeUser.addMembership(membership);
      }
 else {
        formerMembershipIds.remove(membership.getId());
      }
      membership=(Membership)fill(membership,membershipTO,AttributableUtil.MEMBERSHIP,scce);
    }
  }
  for (  Long membershipId : formerMembershipIds) {
    membershipDAO.delete(membershipId);
  }
  return syncopeUser;
}