{"record":{"id":"c2906b9f81e79a78","repo":"apolloconfig/apollo","slug":"operator-should-not-be-null-or-empty","errorCode":null,"errorMessage":"operator should not be null or empty","messagePattern":"operator should not be null or empty","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java","lineNumber":419,"sourceCode":"        KEY_JOINER.join(consumerAppId, TIMESTAMP_FORMAT.format(generationTime), consumerTokenSalt),\n        Charsets.UTF_8).toString();\n  }\n\n  ConsumerRole createConsumerRole(Long consumerId, Long roleId, String operator) {\n    validateOperator(operator);\n    ConsumerRole consumerRole = new ConsumerRole();\n\n    consumerRole.setConsumerId(consumerId);\n    consumerRole.setRoleId(roleId);\n    consumerRole.setDataChangeCreatedBy(operator);\n    consumerRole.setDataChangeLastModifiedBy(operator);\n\n    return consumerRole;\n  }\n\n  private void validateOperator(String operator) {\n    if (Strings.isNullOrEmpty(operator) || operator.trim().isEmpty()) {\n      throw new BadRequestException(\"operator should not be null or empty\");\n    }\n  }\n\n  public Set<String> findAppIdsAuthorizedByConsumerId(long consumerId) {\n    List<ConsumerRole> consumerRoles = this.findConsumerRolesByConsumerId(consumerId);\n    List<Long> roleIds =\n        consumerRoles.stream().map(ConsumerRole::getRoleId).collect(Collectors.toList());\n\n    return this.findAppIdsByRoleIds(roleIds);\n  }\n\n  private List<ConsumerRole> findConsumerRolesByConsumerId(long consumerId) {\n    return this.consumerRoleRepository.findByConsumerId(consumerId);\n  }\n\n  private Set<String> findAppIdsByRoleIds(List<Long> roleIds) {\n    Iterable<Role> roleIterable = this.roleRepository.findAllById(roleIds);\n","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java#L401-L437","documentation":"Thrown by ConsumerService.validateOperator when the operator string is null, empty, or contains only whitespace. This private method is called at the top of every role-assignment and consumer-role-creation method. Apollo requires an operator identifier for audit/data-change tracking (DataChangeCreatedBy / DataChangeLastModifiedBy fields). Results in HTTP 400.","triggerScenarios":"Calling any ConsumerService method that takes an operator parameter (assignCreateApplicationRoleToConsumer, assignManageUsersRoleToConsumer, assignAppRoleToConsumer, assignNamespaceRoleToConsumer, createConsumerRole) with operator = null, operator = \"\", or operator = \"   \".","commonSituations":"An API client omits the operator field from the request body or query parameter. A service-layer caller passes null because the operator was derived from a context holder that was not populated. A test or integration script calls the service directly without setting an operator.","solutions":["Ensure the operator parameter is a non-blank user ID (e.g., the logged-in user's userId) before calling the service method.","If the operator is derived from the request context, validate it early in the controller layer and return a clear error.","For automation/API clients, always include the operator field in the request payload."],"exampleFix":"// before\nconsumerService.assignAppRoleToConsumer(token, appId, null);\n\n// after\nString operator = resolveOperator(request.getOperator());\nif (operator == null || operator.trim().isEmpty()) {\n    throw new BadRequestException(\"operator should not be null or empty\");\n}\nconsumerService.assignAppRoleToConsumer(token, appId, operator);","handlingStrategy":"validation","validationCode":"// Validate operator before calling ConsumerService methods\npublic static String requireOperator(String operator) {\n    if (operator == null || operator.trim().isEmpty()) {\n        throw new IllegalArgumentException(\"operator must be a non-blank user ID\");\n    }\n    return operator.trim();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate operator at the controller/integration boundary before passing to service-layer methods.","For consumer-token requests, always include and validate the operator parameter explicitly.","Use a shared validation utility so all entry points apply the same operator check."],"tags":["openapi","validation","apollo-portal","audit","operator"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}