{"record":{"id":"d4342f0572642196","repo":"apolloconfig/apollo","slug":"params-appid-can-not-be-empty-d4342f","errorCode":null,"errorMessage":"Params(AppId) can not be empty.","messagePattern":"Params\\(AppId\\) can not be empty\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java","lineNumber":142,"sourceCode":"\n  @PreAuthorize(value = \"@unifiedPermissionValidator.isSuperAdmin()\")\n  @GetMapping(value = \"/consumer/info/by-appId\")\n  public ConsumerInfo getConsumerInfoByAppId(@RequestParam String appId) {\n    return consumerService.getConsumerInfoByAppId(appId);\n  }\n\n  @PreAuthorize(value = \"@unifiedPermissionValidator.isSuperAdmin()\")\n  @PostMapping(value = \"/consumers/{token}/assign-role\")\n  public List<ConsumerRole> assignNamespaceRoleToConsumer(@PathVariable String token,\n      @RequestParam String type, @RequestParam(required = false) String envs,\n      @RequestBody NamespaceDTO namespace) {\n    List<ConsumerRole> consumerRoleList = new ArrayList<>(8);\n\n    String appId = namespace.getAppId();\n    String namespaceName = namespace.getNamespaceName();\n\n    if (StringUtils.isEmpty(appId)) {\n      throw new BadRequestException(\"Params(AppId) can not be empty.\");\n    }\n    if (Objects.equals(\"AppRole\", type)) {\n      return Collections.singletonList(consumerService.assignAppRoleToConsumer(token, appId,\n          userInfoHolder.getUser().getUserId()));\n    }\n    if (StringUtils.isEmpty(namespaceName)) {\n      throw new BadRequestException(\"Params(NamespaceName) can not be empty.\");\n    }\n    if (null != envs) {\n      String[] envArray = envs.split(\",\");\n      List<String> envList = Lists.newArrayList();\n      // validate env parameter\n      for (String env : envArray) {\n        if (Strings.isNullOrEmpty(env)) {\n          continue;\n        }\n        if (Env.UNKNOWN.equals(Env.transformEnv(env))) {\n          throw BadRequestException.invalidEnvFormat(env);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java#L124-L160","documentation":"BadRequestException (HTTP 400) from ConsumerController.assignNamespaceRoleToConsumer (POST /consumers/{token}/assign-role). It reads appId from the NamespaceDTO body and rejects the request if appId is null or empty (StringUtils.isEmpty). This check runs before any role assignment, and before the namespaceName check, for the namespace-role branch.","triggerScenarios":"POST /consumers/{token}/assign-role with a NamespaceDTO body whose appId is null, empty, or whitespace-only.","commonSituations":"Client built the body from a namespace that was not loaded; frontend form submitting before appId was selected; JSON using the wrong field name so appId is never populated.","solutions":["Populate namespace.setAppId(<existing app id>) in the body before posting.","Confirm the app exists before assigning a consumer token to it.","Run the emptiness check client-side (see validationCode).","If type='AppRole', note appId is still required before the AppRole branch."],"exampleFix":"// before\nPOST /consumers/{token}/assign-role?type=NAMESPACE\nbody: { \"namespaceName\": \"application\" }   // appId missing -> 400\n\n// after\nbody: { \"appId\": \"sample-app\", \"namespaceName\": \"application\" }","handlingStrategy":"validation","validationCode":"// Require appId on the NamespaceDTO before assign-role.\nString appId = namespaceDto.getAppId();\nif (appId == null || appId.trim().isEmpty()) {\n  throw new IllegalArgumentException(\"appId is required\");\n}\n// namespaceDto.setAppId(<existing app id>) then POST","typeGuard":"static boolean hasAppId(NamespaceDTO dto) {\n  return dto != null && dto.getAppId() != null && !dto.getAppId().trim().isEmpty();\n}","tryCatchPattern":null,"preventionTips":["Always populate appId from a loaded, existing app.","Validate the body before submit using the type guard.","Confirm the app exists before assigning consumer roles.","Reuse the same DTO field name ('appId') the server expects."],"tags":["consumer","validation","role","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}