{"record":{"id":"75bdea4fb4418508","repo":"apolloconfig/apollo","slug":"token-name-can-not-be-blank","errorCode":null,"errorMessage":"Token name can not be blank","messagePattern":"Token name can not be blank","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/UserTokenService.java","lineNumber":359,"sourceCode":"    if (UserTokenOperation.APP_CREATE.equals(operation)) {\n      return userPermissionValidator.hasCreateApplicationPermission();\n    }\n    if (UserTokenOperation.USER_MANAGE.equals(operation)) {\n      return userPermissionValidator.hasManageUsersPermission();\n    }\n    if (UserTokenOperation.SYSTEM_ADMIN.equals(operation)) {\n      return userPermissionValidator.isSuperAdmin();\n    }\n    return false;\n  }\n\n  private Set<String> emptyToNull(Set<String> values) {\n    return values == null || values.isEmpty() ? null : values;\n  }\n\n  private void validateCreateRequest(UserTokenCreateRequest request) {\n    if (request == null || StringUtils.isBlank(request.getName())) {\n      throw new BadRequestException(\"Token name can not be blank\");\n    }\n    if (request.getRateLimit() != null && request.getRateLimit() < 0) {\n      throw BadRequestException.rateLimitIsInvalid();\n    }\n    if (request.getNamespaces() == null) {\n      return;\n    }\n    for (UserTokenNamespaceScope namespaceScope : request.getNamespaces()) {\n      if (namespaceScope == null) {\n        throw new BadRequestException(\"Token namespace scope can not be null\");\n      }\n    }\n  }\n\n  private void validateUserEnabled(String userId) {\n    UserInfo userInfo = userService.findByUserId(userId);\n    if (userInfo == null) {\n      throw BadRequestException.userNotExists(userId);","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/UserTokenService.java#L341-L377","documentation":"Thrown by UserTokenService.validateCreateRequest() when the UserTokenCreateRequest is null or its name field is blank (null, empty, or whitespace-only, checked via StringUtils.isBlank). This is the first validation in createToken(), called before expires, scope, and operator checks. BadRequestException → HTTP 400.","triggerScenarios":"Calling createToken(request, operator) with request=null, request.getName()=null, request.getName()=\"\", or request.getName()=\"   \". This is typically a client-side omission when POSTing to the token creation endpoint.","commonSituations":"Frontend form submits without filling in the token name field. API client constructed programmatically without setting the name. JSON deserialization produces a request object with a missing name field due to a schema mismatch.","solutions":["Set a non-blank name on the UserTokenCreateRequest before calling createToken().","Add client-side validation to require a token name before form submission.","If building the request programmatically, ensure request.setName() is called with a meaningful value."],"exampleFix":"// before\nUserTokenCreateRequest request = new UserTokenCreateRequest();\nrequest.setOperations(Set.of(UserTokenOperation.CONFIG_READ));\n// after\nUserTokenCreateRequest request = new UserTokenCreateRequest();\nrequest.setName(\"ci-deploy-token\");\nrequest.setOperations(Set.of(UserTokenOperation.CONFIG_READ));","handlingStrategy":"validation","validationCode":"if (request == null || StringUtils.isBlank(request.getName())) {\n    throw new IllegalArgumentException(\"Token name is required\");\n}\nuserTokenService.createToken(request, operator);","typeGuard":"static boolean hasValidTokenName(UserTokenCreateRequest request) {\n    return request != null && !StringUtils.isBlank(request.getName());\n}","tryCatchPattern":"try {\n    userTokenService.createToken(request, operator);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"Token name can not be blank\")) {\n        return Response.status(400).entity(\"A non-blank token name is required\").build();\n    }\n    throw e;\n}","preventionTips":["Require a token name field in the UI form with client-side validation.","Set request.setName() explicitly when building requests programmatically."],"tags":["apollo-portal","user-token","validation","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}