Program: 9047
Project: 9047
Buggy source:
/** 
 * Updates an   {@code AMIdentity} in the identity repository with thedetails specified in  {@code identity}.
 * @param identity The updated identity details.
 * @param admin The admin token.
 * @throws ResourceException If a problem occurs.
 */
public void update(IdentityDetails identity,SSOToken admin) throws ResourceException {
  String idName=identity.getName();
  String idType=identity.getType();
  String realm=identity.getRealm();
  if (StringUtils.isEmpty(idName)) {
    throw new BadRequestException("String_Node_Str");
  }
  if (StringUtils.isEmpty(idType)) {
    idType="String_Node_Str";
  }
  if (realm == null) {
    realm="String_Node_Str";
  }
  try {
    IdType objectIdType=getIdType(idType);
    AMIdentityRepository repo=getRepo(admin,realm);
    if (!isOperationSupported(repo,objectIdType,IdOperation.EDIT)) {
      throw new ForbiddenException("String_Node_Str");
    }
    AMIdentity amIdentity=getAMIdentity(admin,repo,idType,idName);
    if (amIdentity == null) {
      String msg="String_Node_Str" + idName + "String_Node_Str"+ idType+ "String_Node_Str";
      throw new NotFoundException(msg);
    }
    if (isSpecialUser(amIdentity)) {
      throw new ForbiddenException("String_Node_Str");
    }
    Map<String,Set<String>> attrs=asMap(identity.getAttributes());
    if (attrs != null && !attrs.isEmpty()) {
      Map<String,Set<String>> idAttrs=new HashMap<>();
      Set<String> removeAttrs=new HashSet<>();
      for (      Map.Entry<String,Set<String>> entry : attrs.entrySet()) {
        String attrName=entry.getKey();
        Set<String> attrValues=entry.getValue();
        if (attrValues != null && !attrValues.isEmpty()) {
          idAttrs.put(attrName,attrValues);
        }
 else {
          removeAttrs.add(attrName);
        }
      }
      boolean storeNeeded=false;
      if (!idAttrs.isEmpty()) {
        amIdentity.setAttributes(idAttrs);
        storeNeeded=true;
      }
      if (!removeAttrs.isEmpty()) {
        amIdentity.removeAttributes(removeAttrs);
        storeNeeded=true;
      }
      if (storeNeeded) {
        amIdentity.store();
      }
    }
    if (IdType.USER.equals(objectIdType)) {
      Set<String> roles=asSet(identity.getRoleList());
      if (!roles.isEmpty()) {
        setMemberships(repo,amIdentity,roles,IdType.ROLE);
      }
      Set<String> groups=asSet(identity.getGroupList());
      if (!groups.isEmpty()) {
        setMemberships(repo,amIdentity,groups,IdType.GROUP);
      }
    }
    if (IdType.GROUP.equals(objectIdType) || IdType.ROLE.equals(objectIdType)) {
      Set<String> members=asSet(identity.getMemberList());
      if (!members.isEmpty()) {
        setMembers(repo,amIdentity,members,IdType.USER);
      }
    }
  }
 catch (  IdRepoException ex) {
    debug.error("String_Node_Str",ex);
    if (LDAPConstants.CONSTRAINT_VIOLATED_ERROR.equals(ex.getErrorCode())) {
      throw new InternalServerErrorException(ex.getConstraintViolationDetails());
    }
    if (LDAPConstants.LDAP_INVALID_SYNTAX.equals(ex.getLDAPErrorCode())) {
      throw new BadRequestException("String_Node_Str");
    }
    throw convertToResourceException(idServicesErrorHandler.handleError(ex));
  }
catch (  SSOException ex) {
    debug.error("String_Node_Str",ex);
    throw new BadRequestException(ex.getMessage());
  }
catch (  ObjectNotFound e) {
    debug.error("String_Node_Str",e);
    throw new NotFoundException(e.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Updates an   {@code AMIdentity} in the identity repository with thedetails specified in  {@code identity}.
 * @param identity The updated identity details.
 * @param admin The admin token.
 * @throws ResourceException If a problem occurs.
 */
public void update(IdentityDetails identity,SSOToken admin) throws ResourceException {
  String idName=identity.getName();
  String idType=identity.getType();
  String realm=identity.getRealm();
  if (StringUtils.isEmpty(idName)) {
    throw new BadRequestException("String_Node_Str");
  }
  if (StringUtils.isEmpty(idType)) {
    idType="String_Node_Str";
  }
  if (realm == null) {
    realm="String_Node_Str";
  }
  try {
    IdType objectIdType=getIdType(idType);
    AMIdentityRepository repo=getRepo(admin,realm);
    if (!isOperationSupported(repo,objectIdType,IdOperation.EDIT)) {
      throw new ForbiddenException("String_Node_Str");
    }
    AMIdentity amIdentity=getAMIdentity(admin,repo,idType,idName);
    if (amIdentity == null) {
      String msg="String_Node_Str" + idName + "String_Node_Str"+ idType+ "String_Node_Str";
      throw new NotFoundException(msg);
    }
    if (isSpecialUser(amIdentity)) {
      throw new ForbiddenException("String_Node_Str");
    }
    Map<String,Set<String>> attrs=asMap(identity.getAttributes());
    if (attrs != null && !attrs.isEmpty()) {
      Map<String,Set<String>> idAttrs=new HashMap<>();
      Set<String> removeAttrs=new HashSet<>();
      for (      Map.Entry<String,Set<String>> entry : attrs.entrySet()) {
        String attrName=entry.getKey();
        Set<String> attrValues=entry.getValue();
        if (attrValues != null && !attrValues.isEmpty()) {
          idAttrs.put(attrName,attrValues);
        }
 else {
          removeAttrs.add(attrName);
        }
      }
      boolean storeNeeded=false;
      if (!idAttrs.isEmpty()) {
        amIdentity.setAttributes(idAttrs);
        storeNeeded=true;
      }
      if (!removeAttrs.isEmpty()) {
        amIdentity.removeAttributes(removeAttrs);
        storeNeeded=true;
      }
      if (storeNeeded) {
        amIdentity.store();
      }
    }
    if (IdType.USER.equals(objectIdType)) {
      Set<String> roles=asSet(identity.getRoleList());
      if (!roles.isEmpty()) {
        setMemberships(repo,amIdentity,roles,IdType.ROLE);
      }
      Set<String> groups=asSet(identity.getGroupList());
      if (!groups.isEmpty()) {
        setMemberships(repo,amIdentity,groups,IdType.GROUP);
      }
    }
    if (IdType.GROUP.equals(objectIdType) || IdType.ROLE.equals(objectIdType)) {
      Set<String> members=asSet(identity.getMemberList());
      if (!members.isEmpty()) {
        setMembers(repo,amIdentity,members,IdType.USER);
      }
    }
  }
 catch (  IdRepoException ex) {
    debug.error("String_Node_Str",ex);
    if (LDAPConstants.CONSTRAINT_VIOLATED_ERROR.equals(ex.getErrorCode())) {
      throw new InternalServerErrorException(ex.getConstraintViolationDetails());
    }
 else     if (LDAPConstants.LDAP_INVALID_SYNTAX.equals(ex.getLDAPErrorCode())) {
      throw new BadRequestException("String_Node_Str");
    }
 else     if (LDAPConstants.ILLEGAL_ARGS_ERROR.equals(ex.getErrorCode())) {
      throw new BadRequestException(ex);
    }
    throw convertToResourceException(idServicesErrorHandler.handleError(ex));
  }
catch (  SSOException ex) {
    debug.error("String_Node_Str",ex);
    throw new BadRequestException(ex.getMessage());
  }
catch (  ObjectNotFound e) {
    debug.error("String_Node_Str",e);
    throw new NotFoundException(e.getMessage());
  }
}