{"record":{"id":"814c6a0c44d165f1","repo":"apolloconfig/apollo","slug":"app-is-null","errorCode":null,"errorMessage":"App is null","messagePattern":"App is null","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java","lineNumber":92,"sourceCode":"    this.consumerAuthUtil = consumerAuthUtil;\n    this.consumerService = consumerService;\n    this.appOpenApiService = appOpenApiService;\n    this.userService = userService;\n    this.userInfoHolder = userInfoHolder;\n    this.rolePermissionService = rolePermissionService;\n    this.unifiedPermissionValidator = unifiedPermissionValidator;\n  }\n\n  /**\n   * @see com.ctrip.framework.apollo.portal.controller.AppController#create(AppModel)\n   */\n  @Transactional\n  @PreAuthorize(value = \"@unifiedPermissionValidator.hasCreateApplicationPermission()\")\n  @ApolloAuditLog(type = OpType.CREATE, name = \"App.create\")\n  @Override\n  public ResponseEntity<Void> createApp(OpenCreateAppDTO req) {\n    if (null == req.getApp()) {\n      throw new BadRequestException(\"App is null\");\n    }\n    final OpenAppDTO app = req.getApp();\n    if (!StringUtils.hasText(app.getAppId())) {\n      throw new BadRequestException(\"AppId is null or blank\");\n    }\n    validatePortalApp(app);\n    String resolvedOperator = resolveOperator(app.getDataChangeCreatedBy());\n    app.setDataChangeCreatedBy(resolvedOperator);\n    app.setDataChangeLastModifiedBy(resolvedOperator);\n    this.appOpenApiService.createApp(req, resolvedOperator);\n    if (Boolean.TRUE.equals(req.getAssignAppRoleToSelf())\n        && UserIdentityConstants.CONSUMER.equals(UserIdentityContextHolder.getAuthType())) {\n      long consumerId = this.consumerAuthUtil.retrieveConsumerIdFromCtx();\n      consumerService.assignAppRoleToConsumer(consumerId, app.getAppId(), resolvedOperator);\n    }\n    return ResponseEntity.ok().build();\n  }\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java#L74-L110","documentation":"Thrown by AppController.createApp when the OpenCreateAppDTO request body's getApp() returns null. The createApp endpoint (POST /openapi/v1/apps or equivalent) expects a nested app object inside the request. If the client sends a body without the app field, or sends an empty JSON object, this guard fires. Results in HTTP 400.","triggerScenarios":"Sending a POST request to create an app with a body like {} or {\"assignAppRoleToSelf\": true} that omits the \"app\" field. Also triggered if the deserialization of the app field fails silently (e.g., wrong JSON structure).","commonSituations":"An API client constructs OpenCreateAppDTO but forgets to call setApp(...). A JSON payload is malformed or the app field is named differently than expected by the OpenAPI spec. A client library version mismatch where the DTO shape changed.","solutions":["Ensure the request body includes a non-null app object with all required fields (appId, name, orgId, orgName, ownerName).","Validate the JSON structure against the OpenAPI spec before sending.","If using the Java client, call req.setApp(openAppDTO) before invoking the API."],"exampleFix":"// before\nOpenCreateAppDTO req = new OpenCreateAppDTO();\nreq.setAssignAppRoleToSelf(true);\n// app field not set\napi.createApp(req);\n\n// after\nOpenAppDTO app = new OpenAppDTO();\napp.setAppId(\"my-app\");\napp.setName(\"My App\");\napp.setOrgId(\"org1\");\napp.setOrgName(\"My Org\");\napp.setOwnerName(\"admin\");\nOpenCreateAppDTO req = new OpenCreateAppDTO();\nreq.setApp(app);\nreq.setAssignAppRoleToSelf(true);\napi.createApp(req);","handlingStrategy":"validation","validationCode":"// Validate the request before calling createApp\nif (req == null || req.getApp() == null) {\n    throw new IllegalArgumentException(\"Request must contain a non-null app object\");\n}\nappOpenApiService.createApp(req, operator);","typeGuard":"public static boolean isValidCreateAppRequest(OpenCreateAppDTO req) {\n    return req != null && req.getApp() != null;\n}","tryCatchPattern":null,"preventionTips":["Always construct and set the app object in OpenCreateAppDTO before sending.","Add client-side validation that checks for a non-null app object with required fields.","Use the generated OpenAPI client classes to ensure correct DTO construction."],"tags":["openapi","app-creation","validation","apollo-portal","request-body"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}