{"record":{"id":"c1f5f10c3f583eb8","repo":"iflytek/astron-agent","slug":"8330-toolbox-import-file-name-null","errorCode":"8330","errorMessage":"toolbox.import.file.name.null","messagePattern":"toolbox\\.import\\.file\\.name\\.null","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java","lineNumber":2274,"sourceCode":"            throw new BusinessException(ResponseEnum.TOOLBOX_EXPORT_ERROR);\n        }\n    }\n\n    /**\n     * Import tool from JSON or YAML file\n     *\n     * @param file Uploaded file\n     * @return ToolBoxExportVo\n     */\n    public Object importTool(org.springframework.web.multipart.MultipartFile file) {\n        try {\n            // Check file type\n            String fileName = file.getOriginalFilename();\n            ObjectMapper jsonMapper = new ObjectMapper();\n            ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());\n\n            if (fileName == null) {\n                throw new BusinessException(ResponseEnum.TOOLBOX_IMPORT_FILE_NAME_NULL);\n            }\n\n            String lowerName = fileName.toLowerCase();\n\n            ToolBoxExportVo vo;\n            if (lowerName.endsWith(\".yaml\") || lowerName.endsWith(\".yml\")) {\n                // YAML -> ToolBoxExportVo\n                vo = yamlMapper.readValue(file.getInputStream(), ToolBoxExportVo.class);\n            } else if (lowerName.endsWith(\".json\")) {\n                // JSON -> ToolBoxExportVo\n                vo = jsonMapper.readValue(file.getInputStream(), ToolBoxExportVo.class);\n            } else {\n                throw new BusinessException(ResponseEnum.TOOLBOX_IMPORT_FILE_FORMAT_ERROR);\n            }\n            return vo;\n        } catch (Exception ex) {\n            log.error(\"Import failed\", ex);\n            if (ex instanceof BusinessException) {","sourceCodeStart":2256,"sourceCodeEnd":2292,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java#L2256-L2292","documentation":"TOOLBOX_IMPORT_FILE_NAME_NULL (code 8330) is thrown when the uploaded MultipartFile's getOriginalFilename() returns null. The service needs the filename to decide whether the file is YAML (.yaml/.yml) or JSON (.json), so an unnamed file cannot be routed to a parser.","triggerScenarios":"Posting a multipart import request where the file part has no filename, e.g. programmatically built MultipartFile without a filename, or a client that omits the filename in Content-Disposition.","commonSituations":"Scripts or tests constructing MockMultipartFile/ByteArrayMultipartFile without setting a name; proxies or custom HTTP clients stripping the filename header.","solutions":["Send the multipart part with a proper filename ending in .yaml/.yml or .json","In test code, pass a filename when constructing the MockMultipartFile","Fix the client so the file's original name is preserved in the upload"],"exampleFix":"// before\nnew MockMultipartFile(\"file\", null, \"application/json\", bytes)\n// after\nnew MockMultipartFile(\"file\", \"tool.json\", \"application/json\", bytes)","handlingStrategy":"validation","validationCode":"if (file == null || file.getOriginalFilename() == null || file.getOriginalFilename().isBlank()) { throw new IllegalArgumentException(\"uploaded file must have a filename\"); }","typeGuard":"boolean hasFileName(MultipartFile f) { return f != null && f.getOriginalFilename() != null && !f.getOriginalFilename().isEmpty(); }","tryCatchPattern":"try { toolBoxApi.importTool(file); } catch (BusinessException e) { if (e.getCode() == 8330) { /* prompt user to re-upload with a named file */ } else throw e; }","preventionTips":["Always set a filename when constructing multipart parts in tests/scripts","Avoid proxies/custom clients that strip Content-Disposition filenames","Validate the upload client sends originalFilename"],"tags":["java","spring-boot","upload","validation","toolbox"],"backgroundTag":"missing-required-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"}