{"record":{"id":"1735e0860ab93361","repo":"iflytek/astron-agent","slug":"file-empty","errorCode":"FILE_EMPTY","errorMessage":"FILE_EMPTY","messagePattern":"FILE_EMPTY","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AudioValidator.java","lineNumber":48,"sourceCode":"    private static final int REQUIRED_CHANNELS = 1;\n    // 24kHz\n    private static final float MIN_SAMPLE_RATE = 24000.0f;\n    // 16bit\n    private static final int REQUIRED_SAMPLE_SIZE = 16;\n    // 40 seconds\n    private static final int MAX_DURATION_SECONDS = 40;\n    // 3MB\n    private static final long MAX_FILE_SIZE_BYTES = 3 * 1024 * 1024;\n\n    /**\n     * Validate audio file\n     *\n     * @param file uploaded file\n     * @throws BusinessException throws business exception when validation fails\n     */\n    public static void validateAudioFile(MultipartFile file) throws BusinessException {\n        if (file == null || file.isEmpty()) {\n            throw new BusinessException(ResponseEnum.FILE_EMPTY);\n        }\n\n        // 1. Check file format\n        validateFileFormat(file);\n\n        // 2. Check file size\n        validateFileSize(file);\n\n        // 3. Check audio properties\n        validateAudioProperties(file);\n    }\n\n    /**\n     * Validate file format\n     */\n    private static void validateFileFormat(MultipartFile file) throws BusinessException {\n        String filename = file.getOriginalFilename();\n        if (filename == null) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AudioValidator.java#L30-L66","documentation":"BusinessException(ResponseEnum.FILE_EMPTY) thrown at the top of AudioValidator.validateAudioFile when the uploaded MultipartFile is null or isEmpty(). The validator refuses to process any upload that carries no bytes, before format/size/audio-property checks run. It is the first gate of the audio upload validation chain.","triggerScenarios":"POSTing a multipart request to an audio upload endpoint with an empty file part, a zero-byte file, omitting the file field entirely (file == null), or a client that sends the part name but no content.","commonSituations":"Frontend forms submitted without the user picking a file; curl commands using -F \"file=@empty.wav\" with a 0-byte file; HTML form field name mismatch causing Spring to bind null; interrupted uploads that produce empty parts.","solutions":["Select a real, non-empty audio file in the client before submitting the request.","Check the multipart field name matches the controller parameter (e.g. \"file\") so Spring binds the part.","Verify curl/HTTP client flags: use -F \"file=@recording.wav\" (not -d) so the body is sent as multipart with content.","Server-side: return the FILE_EMPTY message to the client so the UI can prompt for a valid file instead of retrying blindly."],"exampleFix":"// before\ncurl -X POST http://host/audio -d \"file=@empty.wav\"\n// after\ncurl -X POST http://host/audio -F \"file=@recording.wav\"","handlingStrategy":"validation","validationCode":"if (file == null || file.isEmpty() || file.getSize() == 0) { alert('Please select a non-empty audio file'); return; }","typeGuard":"boolean hasFile(MultipartFile f) { return f != null && !f.isEmpty(); }","tryCatchPattern":"try { AudioValidator.validateAudioFile(file); }\ncatch (BusinessException e) { if (ResponseEnum.FILE_EMPTY.equals(e.getResponseEnum())) { /* 400: prompt user to pick a file */ } else { throw e; } }","preventionTips":["Make the file input required in the UI and validate before submit.","Check file.size > 0 client-side before uploading.","Ensure the form field name matches the controller's MultipartFile parameter.","Use multipart encoding (enctype=\"multipart/form-data\") on the form."],"tags":["java","upload","validation","multipart"],"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"}