{"record":{"id":"aa819eb87523a266","repo":"apolloconfig/apollo","slug":"operator-should-not-be-null-or-empty-aa819e","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":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java","lineNumber":90,"sourceCode":"      final RolePermissionService rolePermissionService, final FavoriteService favoriteService,\n      final UserService userService, ApplicationEventPublisher publisher,\n      final ApolloAuditLogApi apolloAuditLogApi, PortalSettings portalSettings) {\n    this.appAPI = appAPI;\n    this.appRepository = appRepository;\n    this.clusterService = clusterService;\n    this.appNamespaceService = appNamespaceService;\n    this.roleInitializationService = roleInitializationService;\n    this.rolePermissionService = rolePermissionService;\n    this.favoriteService = favoriteService;\n    this.userService = userService;\n    this.apolloAuditLogApi = apolloAuditLogApi;\n    this.publisher = publisher;\n    this.portalSettings = portalSettings;\n  }\n\n  private static void validateOperator(String operator) {\n    if (StringUtils.isBlank(operator)) {\n      throw new BadRequestException(\"operator should not be null or empty\");\n    }\n  }\n\n  public List<App> findAll() {\n    Iterable<App> apps = appRepository.findAll();\n\n    return Lists.newArrayList(apps);\n  }\n\n  public PageDTO<App> findAll(Pageable pageable) {\n    Page<App> apps = appRepository.findAll(pageable);\n\n    return new PageDTO<>(apps.getContent(), pageable, apps.getTotalElements());\n  }\n\n  public PageDTO<App> searchByAppIdOrAppName(String query, Pageable pageable) {\n    Page<App> apps = appRepository.findByAppIdContainingOrNameContaining(query, query, pageable);\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java#L72-L108","documentation":"Thrown by AppService.validateOperator when the operator string is blank (StringUtils.isBlank). Called from createAppInLocal and the update path as the first guard. BadRequestException → HTTP 400. The operator is normally the logged-in user id propagated by the controller; a blank value indicates the caller context was lost.","triggerScenarios":"Calling createAppInLocal/updateApp with a null/empty/whitespace operator — e.g. controller passed null because the UserInfoHolder had no user, or a service-layer caller omitted the operator argument.","commonSituations":"Anonymous/unauthenticated call reaching the service layer; a test or job invokes AppService directly without setting an operator; a custom controller forgets to pass userInfoHolder.getUser().getUserId().","solutions":["Ensure the acting user's userId is always passed as operator (typically from UserInfoHolder).","Reject requests at the controller layer when no authenticated user is present.","In jobs/scripts, pass an explicit service-account operator id."],"exampleFix":"// before\nappService.createAppInLocal(app, null);\n\n// after\nString operator = userInfoHolder.getUser().getUserId();\nif (StringUtils.isBlank(operator)) {\n  throw new AccessDeniedException(\"no authenticated operator\");\n}\nappService.createAppInLocal(app, operator);","handlingStrategy":"validation","validationCode":"String operator = userInfoHolder.getUser().getUserId();\nif (StringUtils.isBlank(operator)) {\n  return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(\"no authenticated operator\");\n}","typeGuard":"boolean hasOperator(String op) { return !StringUtils.isBlank(op); }","tryCatchPattern":null,"preventionTips":["Always propagate the authenticated userId as operator from controllers.","Block anonymous access from reaching the service layer.","Pass an explicit service-account id in jobs/scripts."],"tags":["apollo-portal","app-service","validation","operator"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}