{"record":{"id":"079c965f83478ce2","repo":"iflytek/astron-agent","slug":"database-id-cannot-empty","errorCode":"DATABASE_ID_CANNOT_EMPTY","errorMessage":"DATABASE_ID_CANNOT_EMPTY","messagePattern":"DATABASE_ID_CANNOT_EMPTY","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":347,"sourceCode":"            // Save to core system\n            String ddl = buildDDL(dbTableDto, DBOperateEnum.INSERT.getCode(), null);\n            // Call core system to create table\n            for (String stmt : safeSplitStatements(ddl)) {\n                SqlRenderer.denyMultiStmtOrComment(stmt); // At this point each statement does not contain semicolon\n                coreSystemService.execDDL(stmt, UserInfoManagerHandler.getUserId(), SpaceInfoUtil.getSpaceId(), dbInfo.getDbId());\n            }\n        } catch (Exception ex) {\n            log.error(\"Failed to create table, params={}\", dbTableDto, ex);\n            throw new BusinessException(ResponseEnum.DATABASE_TABLE_CREATE_FAILED);\n        }\n\n    }\n\n\n    public List<DbTableVo> getDbTableList(Long dbId) {\n        try {\n            if (dbId == null) {\n                throw new BusinessException(ResponseEnum.DATABASE_ID_CANNOT_EMPTY);\n            }\n            dataPermissionCheckTool.checkDbBelong(dbId);\n            List<DbTable> dbTables = dbTableMapper.selectList(new QueryWrapper<DbTable>().lambda()\n                    .eq(DbTable::getDbId, dbId)\n                    .orderByDesc(DbTable::getCreateTime)\n                    .eq(DbTable::getDeleted, false));\n            List<DbTableVo> dbTableVos = new ArrayList<>();\n            dbTables.forEach(dbTable -> {\n                DbTableVo dbTableVo = new DbTableVo();\n                BeanUtils.copyProperties(dbTable, dbTableVo);\n                dbTableVos.add(dbTableVo);\n            });\n            return dbTableVos;\n        } catch (Exception ex) {\n            log.error(\"Failed to get table list, dbId={}\", dbId, ex);\n            throw new BusinessException(ResponseEnum.DATABASE_TABLE_QUERY_LIST_FAILED);\n        }\n    }","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L329-L365","documentation":"Thrown by DatabaseService.getDbTableList when the dbId parameter is null. Listing tables for a database requires an explicit database id; without it the service cannot scope the query (and would fail the data-permission check).","triggerScenarios":"Calling the table-list endpoint without the dbId query/path parameter, or invoking getDbTableList(null) directly; frontend calls with an unselected database.","commonSituations":"Frontend navigates to table list before choosing a database; API client omits the dbId parameter; a variable holding the selected DB id is undefined/null.","solutions":["Always pass a valid dbId when requesting the table list","In the UI, require database selection before rendering the table list","Check that the client variable holding dbId is populated before the request"],"exampleFix":"// before\ngetDbTableList(null)\n// after\nif (dbId == null) { selectDatabaseFirst(); }\ngetDbTableList(dbId);","handlingStrategy":"validation","validationCode":"if (dbId == null) {\n    throw new IllegalArgumentException(\"dbId is required to list tables\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    databaseService.getDbTableList(dbId);\n} catch (BusinessException e) {\n    if (\"DATABASE_ID_CANNOT_EMPTY\".equals(e.getCode())) { /* redirect user to select a database */ }\n    throw e;\n}","preventionTips":["Always require database selection before fetching its tables","Mark dbId as required in the API contract/OpenAPI schema","Guard client code against undefined/null database ids"],"tags":["validation","database","missing-parameter"],"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"}