{"record":{"id":"0d306a8d7399cb20","repo":"iflytek/astron-agent","slug":"database-name-not-empty","errorCode":"DATABASE_NAME_NOT_EMPTY","errorMessage":"DATABASE_NAME_NOT_EMPTY","messagePattern":"DATABASE_NAME_NOT_EMPTY","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"warning","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":107,"sourceCode":"    @Autowired\n    private DSLContext dslCon;\n    @Autowired\n    private CommonConfig commonConfig;\n\n    @Autowired\n    private DbDialect dialect;\n\n    private static final String[] SYSTEM_FIELDS = {\"id\", \"uid\", \"create_time\"};\n    // New additions in DatabaseService\n    private static final int MAX_PAGE_SIZE = 1000; // Prevent explosion\n    private static final int MAX_EXPORT_IDS = 1000; // IN clause limit\n\n    @Transactional\n    public DbInfo create(DatabaseDto databaseDto) {\n        try {\n            // Required field validation\n            if (!StringUtils.isNotBlank(databaseDto.getName())) {\n                throw new BusinessException(ResponseEnum.DATABASE_NAME_NOT_EMPTY);\n            }\n            String userId = Objects.requireNonNull(UserInfoManagerHandler.getUserId()).toString();\n            Long spaceId = SpaceInfoUtil.getSpaceId();\n            // Duplicate name validation\n            Long count = 0L;\n            if (spaceId == null) {\n                count = dbInfoMapper.selectCount(new QueryWrapper<DbInfo>().lambda()\n                        .eq(DbInfo::getName, databaseDto.getName())\n                        .eq(DbInfo::getSpaceId, null)\n                        .eq(DbInfo::getUid, userId)\n                        .eq(DbInfo::getDeleted, false));\n            } else {\n                count = dbInfoMapper.selectCount(new QueryWrapper<DbInfo>().lambda()\n                        .eq(DbInfo::getName, databaseDto.getName())\n                        .eq(DbInfo::getUid, userId)\n                        .eq(DbInfo::getSpaceId, spaceId)\n                        .eq(DbInfo::getDeleted, false));\n            }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L89-L125","documentation":"Thrown by DatabaseService.create when the incoming DatabaseDto has a null, empty, or whitespace-only name. The service requires every new database record to carry a non-blank display name before it validates duplicates or calls the core system. It is a fail-fast input validation guard, not a system fault.","triggerScenarios":"Calling POST database-create (DatabaseService.create) with a DatabaseDto whose name field is null, \"\" or all whitespace.","commonSituations":"Frontend form submitted without filling the name field; API client omits 'name' in the JSON body; a script sends a DTO built from an optional field that defaulted to null; request deserialization silently drops the name key.","solutions":["Set a non-blank name on DatabaseDto before calling create","Add a required/not-blank validation on the frontend form for the name field","Check the request payload actually contains the 'name' key (correct JSON field naming)","If building DTO programmatically, default or reject null names at the call site"],"exampleFix":"// before\nDatabaseDto dto = new DatabaseDto();\ndto.setDescription(\"analytics\");\ndatabaseService.create(dto); // throws DATABASE_NAME_NOT_EMPTY\n// after\nDatabaseDto dto = new DatabaseDto();\ndto.setName(\"analytics-db\");\ndatabaseService.create(dto);","handlingStrategy":"validation","validationCode":"if (dto == null || dto.getName() == null || dto.getName().isBlank()) {\n    throw new IllegalArgumentException(\"Database name is required\");\n}\ndatabaseService.create(dto);","typeGuard":"boolean hasName(DatabaseDto dto) { return dto != null && dto.getName() != null && !dto.getName().trim().isEmpty(); }","tryCatchPattern":"try { databaseService.create(dto); } catch (BusinessException e) { if (\"DATABASE_NAME_NOT_EMPTY\".equals(e.getCode())) { /* prompt for name */ } else { throw e; } }","preventionTips":["Mark name as required in forms and API schemas","Use @NotBlank on DatabaseDto.name for bean validation","Unit test create with null/empty/whitespace names"],"tags":["validation","input","java","spring"],"backgroundTag":"empty-required-field","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"}