{"record":{"id":"74a5e08d1fd19491","repo":"iflytek/astron-agent","slug":"user-id-cannot-be-null","errorCode":null,"errorMessage":"User ID cannot be null","messagePattern":"User ID cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/dto/bot/BotQueryCondition.java","lineNumber":140,"sourceCode":"     * Check if there is status filtering\n     */\n    public boolean hasPublishStatus() {\n        return publishStatus != null && !publishStatus.isEmpty();\n    }\n\n    /**\n     * Get publish status list (simplified version, only supports 0=offline, 1=online)\n     */\n    public List<Integer> getPublishStatus() {\n        return publishStatus;\n    }\n\n    /**\n     * Validate required parameters\n     */\n    public void validate() {\n        if (uid == null) {\n            throw new IllegalArgumentException(\"User ID cannot be null\");\n        }\n        this.sortDirection = getSafeSortDirection();\n    }\n\n    /**\n     * Convert to query parameters Map\n     *\n     * @return Query parameters for Mapper queries\n     */\n    public Map<String, Object> toQueryParams() {\n        Map<String, Object> params = new HashMap<>();\n\n        // Basic parameters\n        params.put(\"uid\", this.uid);\n        params.put(\"spaceId\", this.spaceId);\n\n        // Search conditions\n        if (this.keyword != null && !this.keyword.trim().isEmpty()) {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/dto/bot/BotQueryCondition.java#L122-L158","documentation":"BotQueryCondition.validate() enforces that the uid field is set before a bot list query is executed, then normalizes the sort direction. A null uid means the query cannot be scoped to a user, so it throws IllegalArgumentException immediately.","triggerScenarios":"Building a BotQueryCondition without calling setUid/setter for uid (or passing a null from the controller) before invoking getBotList; programmatic use of the condition object in validateNormalizesMaliciousSortDirection tests or other callers skipping population.","commonSituations":"Controller code forgetting to copy the authenticated UID into the condition object; refactors that removed uid population; calling getBotList from scheduled jobs or internal services with no user context.","solutions":["Populate BotQueryCondition.uid from the authenticated user (RequestContextUtil.getUID()) before calling validate/getBotList","Add controller-level validation so requests missing the user context are rejected early","Check any new call path to getBotList for uid assignment","Catch IllegalArgumentException in the API layer and map to a 400 response"],"exampleFix":"// before\nBotQueryCondition cond = new BotQueryCondition();\ncond.setName(name);\nbotService.getBotList(cond);\n// after\nBotQueryCondition cond = new BotQueryCondition();\ncond.setUid(RequestContextUtil.getUID());\ncond.setName(name);\nbotService.getBotList(cond);","handlingStrategy":"validation","validationCode":"BotQueryCondition cond = new BotQueryCondition(); if (cond.getUid() == null) { cond.setUid(RequestContextUtil.getUID()); }","typeGuard":"boolean hasUid(BotQueryCondition c) { return c.getUid() != null; }","tryCatchPattern":"try { botService.getBotList(cond); } catch (IllegalArgumentException e) { return badRequest(\"uid is required\"); }","preventionTips":["Always populate query conditions from authenticated context in a single factory/helper","Add bean validation on condition objects before use","Add a regression test asserting getBotList rejects null uid cleanly"],"tags":["null-argument","validation","query-condition"],"backgroundTag":"null-argument","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"}