iflytek/astron-agent · error · IllegalArgumentException

User ID cannot be null

Error message

User ID cannot be null

What it means

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.

Solutions

  1. Populate BotQueryCondition.uid from the authenticated user (RequestContextUtil.getUID()) before calling validate/getBotList
  2. Add controller-level validation so requests missing the user context are rejected early
  3. Check any new call path to getBotList for uid assignment
  4. Catch IllegalArgumentException in the API layer and map to a 400 response

Example fix

// before
BotQueryCondition cond = new BotQueryCondition();
cond.setName(name);
botService.getBotList(cond);
// after
BotQueryCondition cond = new BotQueryCondition();
cond.setUid(RequestContextUtil.getUID());
cond.setName(name);
botService.getBotList(cond);
Defensive patterns

Strategy: validation

Validate before calling

BotQueryCondition cond = new BotQueryCondition(); if (cond.getUid() == null) { cond.setUid(RequestContextUtil.getUID()); }

Type guard

boolean hasUid(BotQueryCondition c) { return c.getUid() != null; }

Try / catch

try { botService.getBotList(cond); } catch (IllegalArgumentException e) { return badRequest("uid is required"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/74a5e08d1fd19491. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/commons/src/main/java/com/iflytek/astron/console/commons/dto/bot/BotQueryCondition.java:140

     * Check if there is status filtering
     */
    public boolean hasPublishStatus() {
        return publishStatus != null && !publishStatus.isEmpty();
    }

    /**
     * Get publish status list (simplified version, only supports 0=offline, 1=online)
     */
    public List<Integer> getPublishStatus() {
        return publishStatus;
    }

    /**
     * Validate required parameters
     */
    public void validate() {
        if (uid == null) {
            throw new IllegalArgumentException("User ID cannot be null");
        }
        this.sortDirection = getSafeSortDirection();
    }

    /**
     * Convert to query parameters Map
     *
     * @return Query parameters for Mapper queries
     */
    public Map<String, Object> toQueryParams() {
        Map<String, Object> params = new HashMap<>();

        // Basic parameters
        params.put("uid", this.uid);
        params.put("spaceId", this.spaceId);

        // Search conditions
        if (this.keyword != null && !this.keyword.trim().isEmpty()) {

View on GitHub (pinned to 5e758547a8)