Program: 37023
Project: 37023
Buggy source:
/** 
 * Update the user resource by sequence of operations.
 * @param existingId
 * @param scimObjectString
 * @param userManager
 * @param attributes
 * @param excludeAttributes
 * @return
 */
public SCIMResponse updateWithPATCH(String existingId,String scimObjectString,UserManager userManager,String attributes,String excludeAttributes){
  try {
    JSONDecoder decoder=getDecoder();
    JSONEncoder encoder=getEncoder();
    List<PatchOperation> opList=decoder.decodeRequest(scimObjectString);
    SCIMResourceTypeSchema schema=SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
    User oldUser=userManager.getMe(existingId,ResourceManagerUtil.getAllAttributeURIs(schema));
    if (oldUser == null) {
      throw new NotFoundException("String_Node_Str");
    }
    User copyOfOldUser=(User)CopyUtil.deepCopy(oldUser);
    User originalUser=(User)CopyUtil.deepCopy(copyOfOldUser);
    User newUser=null;
    for (    PatchOperation operation : opList) {
      if (operation.getOperation().equals(SCIMConstants.OperationalConstants.ADD)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchAdd(operation,getDecoder(),oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchAdd(operation,getDecoder(),newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else       if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REMOVE)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchRemove(operation,oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchRemove(operation,newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else       if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REPLACE)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchReplace(operation,getDecoder(),oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchReplace(operation,getDecoder(),newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else {
        throw new BadRequestException("String_Node_Str",ResponseCodeConstants.INVALID_SYNTAX);
      }
    }
    Map<String,Boolean> requiredAttributes=ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema)CopyUtil.deepCopy(schema),attributes,excludeAttributes);
    if (userManager != null) {
      if (oldUser != null) {
        User validatedUser=(User)ServerSideValidator.validateUpdatedSCIMObject(originalUser,newUser,schema);
        newUser=userManager.updateMe(validatedUser,requiredAttributes);
      }
 else {
        String error="String_Node_Str" + existingId;
        throw new NotFoundException(error);
      }
    }
 else {
      String error="String_Node_Str";
      throw new InternalErrorException(error);
    }
    String encodedUser;
    Map<String,String> httpHeaders=new HashMap<String,String>();
    if (newUser != null) {
      User copiedUser=(User)CopyUtil.deepCopy(newUser);
      ServerSideValidator.validateReturnedAttributes(copiedUser,attributes,excludeAttributes);
      encodedUser=getEncoder().encodeSCIMObject(copiedUser);
      httpHeaders.put(SCIMConstants.LOCATION_HEADER,getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "String_Node_Str" + newUser.getId());
      httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER,SCIMConstants.APPLICATION_JSON);
    }
 else {
      String error="String_Node_Str";
      throw new CharonException(error);
    }
    return new SCIMResponse(ResponseCodeConstants.CODE_OK,encodedUser,httpHeaders);
  }
 catch (  NotFoundException e) {
    return encodeSCIMException(e);
  }
catch (  BadRequestException e) {
    return encodeSCIMException(e);
  }
catch (  NotImplementedException e) {
    return encodeSCIMException(e);
  }
catch (  CharonException e) {
    return encodeSCIMException(e);
  }
catch (  InternalErrorException e) {
    return encodeSCIMException(e);
  }
catch (  Exception e) {
    CharonException e1=new CharonException("String_Node_Str",e);
    return encodeSCIMException(e1);
  }
}

Fixed version (ground truth):
/** 
 * Update the user resource by sequence of operations.
 * @param existingId
 * @param scimObjectString
 * @param userManager
 * @param attributes
 * @param excludeAttributes
 * @return
 */
public SCIMResponse updateWithPATCH(String existingId,String scimObjectString,UserManager userManager,String attributes,String excludeAttributes){
  try {
    if (userManager == null) {
      String error="String_Node_Str";
      throw new InternalErrorException(error);
    }
    JSONDecoder decoder=getDecoder();
    List<PatchOperation> opList=decoder.decodeRequest(scimObjectString);
    SCIMResourceTypeSchema schema=SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
    User oldUser=userManager.getMe(existingId,ResourceManagerUtil.getAllAttributeURIs(schema));
    if (oldUser == null) {
      throw new NotFoundException("String_Node_Str");
    }
    User copyOfOldUser=(User)CopyUtil.deepCopy(oldUser);
    User originalUser=(User)CopyUtil.deepCopy(copyOfOldUser);
    User newUser=null;
    for (    PatchOperation operation : opList) {
      if (operation.getOperation().equals(SCIMConstants.OperationalConstants.ADD)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchAdd(operation,getDecoder(),oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchAdd(operation,getDecoder(),newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else       if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REMOVE)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchRemove(operation,oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchRemove(operation,newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else       if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REPLACE)) {
        if (newUser == null) {
          newUser=(User)PatchOperationUtil.doPatchReplace(operation,getDecoder(),oldUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
 else {
          newUser=(User)PatchOperationUtil.doPatchReplace(operation,getDecoder(),newUser,copyOfOldUser,schema);
          copyOfOldUser=(User)CopyUtil.deepCopy(newUser);
        }
      }
 else {
        throw new BadRequestException("String_Node_Str",ResponseCodeConstants.INVALID_SYNTAX);
      }
    }
    Map<String,Boolean> requiredAttributes=ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema)CopyUtil.deepCopy(schema),attributes,excludeAttributes);
    User validatedUser=(User)ServerSideValidator.validateUpdatedSCIMObject(originalUser,newUser,schema);
    newUser=userManager.updateMe(validatedUser,requiredAttributes);
    String encodedUser;
    Map<String,String> httpHeaders=new HashMap<String,String>();
    if (newUser != null) {
      User copiedUser=(User)CopyUtil.deepCopy(newUser);
      ServerSideValidator.validateReturnedAttributes(copiedUser,attributes,excludeAttributes);
      encodedUser=getEncoder().encodeSCIMObject(copiedUser);
      httpHeaders.put(SCIMConstants.LOCATION_HEADER,getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "String_Node_Str" + newUser.getId());
      httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER,SCIMConstants.APPLICATION_JSON);
    }
 else {
      String error="String_Node_Str";
      throw new CharonException(error);
    }
    return new SCIMResponse(ResponseCodeConstants.CODE_OK,encodedUser,httpHeaders);
  }
 catch (  NotFoundException e) {
    return encodeSCIMException(e);
  }
catch (  BadRequestException e) {
    return encodeSCIMException(e);
  }
catch (  NotImplementedException e) {
    return encodeSCIMException(e);
  }
catch (  CharonException e) {
    return encodeSCIMException(e);
  }
catch (  InternalErrorException e) {
    return encodeSCIMException(e);
  }
catch (  RuntimeException e) {
    CharonException e1=new CharonException("String_Node_Str",e);
    return encodeSCIMException(e1);
  }
}