{"record":{"id":"ca09d8ed0dfade48","repo":"iflytek/astron-agent","slug":"data-not-exist-ca09d8","errorCode":"DATA_NOT_EXIST","errorMessage":"DATA_NOT_EXIST","messagePattern":"DATA_NOT_EXIST","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/tool/DataPermissionCheckTool.java","lineNumber":144,"sourceCode":"                \"Permission check failed: action={}, uid={}, currentSpaceId={}, resourceType={}\",\n                action,\n                uid,\n                currentSpaceId(),\n                resource == null ? null : resource.getClass().getSimpleName());\n        throw new BusinessException(ResponseEnum.EXCEED_AUTHORITY);\n    }\n\n    // ===================== Repo / Tool / File =====================\n\n    /**\n     * Check repository ownership.\n     *\n     * @param repo the repository to check\n     * @throws BusinessException if access denied or data not exists\n     */\n    public void checkRepoBelong(Repo repo) {\n        if (repo == null)\n            throw new BusinessException(ResponseEnum.DATA_NOT_EXIST);\n        String uid = getThreadLocalUidNoNull();\n        Long spaceId = currentSpaceId();\n\n        boolean noPermission = spaceId != null\n                ? !Objects.equals(repo.getSpaceId(), spaceId)\n                : !Objects.equals(repo.getUserId(), uid.toString());\n\n        if (noPermission)\n            deny(\"checkRepoBelong\", repo);\n    }\n\n    /**\n     * Check repository visibility (supports space visibility/user visibility).\n     *\n     * @param repo the repository to check\n     * @throws BusinessException if access denied or data not exists\n     */\n    public void checkRepoVisible(Repo repo) {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/tool/DataPermissionCheckTool.java#L126-L162","documentation":"DataPermissionCheckTool.checkRepoBelong throws BusinessException(ResponseEnum.DATA_NOT_EXIST) when the Repo argument is null. The method is a permission gate: after the null check it compares the repo's spaceId/userId against the current request's space/uid and also throws DATA_NOT_EXIST (or denies) when ownership does not match. The intent is to make a non-existent record and a record the caller may not see indistinguishable.","triggerScenarios":"Calling checkRepoBelong(repo) with a repo loaded by repoMapper.selectById(id) that returned null — i.e. an id that does not exist in the repo table, a soft-deleted repo, a wrong-tenant/space id, or an id from a stale client reference.","commonSituations":"Client passes a deleted or mistyped repository id; DB row was removed between listing and access; caller forgot a null check after selectById before invoking the permission tool; cross-space reference leaks an id the user never owned.","solutions":["Verify the repo id exists with repoMapper.selectById(id) before calling checkRepoBelong, and return a 404 to the client if null","Check the request payload/path variable — a missing or malformed repoId resolves to no row","Confirm the row is not soft-deleted and belongs to the environment/space you are querying against","Catch BusinessException with code DATA_NOT_EXIST at the controller layer and map it to HTTP 404"],"exampleFix":"// before\nRepo repo = repoMapper.selectById(id);\ndataPermissionCheckTool.checkRepoBelong(repo);\n\n// after\nRepo repo = repoMapper.selectById(id);\nif (repo == null) {\n    throw new BusinessException(ResponseEnum.DATA_NOT_EXIST); // or return 404\n}\ndataPermissionCheckTool.checkRepoBelong(repo);","handlingStrategy":"try-catch","validationCode":"Repo repo = repoMapper.selectById(repoId);\nif (repo == null) { throw new BusinessException(ResponseEnum.DATA_NOT_EXIST); }","typeGuard":"if (repo != null) { dataPermissionCheckTool.checkRepoBelong(repo); }","tryCatchPattern":"try {\n    dataPermissionCheckTool.checkRepoBelong(repo);\n} catch (BusinessException e) {\n    if (ResponseEnum.DATA_NOT_EXIST.getCode().equals(e.getCode())) {\n        return ResponseEntity.notFound().build();\n    }\n    throw e;\n}","preventionTips":["Always null-check mapper lookup results before calling permission tools","Return 404 (not 500) when the entity is absent","Clean up dependent records when deleting repos to avoid stale references","Log the failing entity id to speed up triage"],"tags":["java","spring-boot","permissions","null-check","repository"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}