{"record":{"id":"691329e2c2313552","repo":"iflytek/astron-agent","slug":"base64-string-cannot-be-empty","errorCode":null,"errorMessage":"Base64 string cannot be empty","messagePattern":"Base64 string cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java","lineNumber":30,"sourceCode":"\nimport static com.iflytek.astron.console.commons.constant.ResponseEnum.SYSTEM_ERROR;\n\n/**\n * Image processing utility class\n *\n */\n@Slf4j\npublic class ImageUtil {\n\n    /**\n     * Convert base64 string to InputStream\n     *\n     * @param base64String Base64 encoded image string\n     * @return InputStream object\n     */\n    public static InputStream base64ToImageInputStream(String base64String) {\n        if (base64String == null || base64String.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"Base64 string cannot be empty\");\n        }\n\n        try {\n            byte[] byteArray = Base64.getDecoder().decode(base64String);\n            return new ByteArrayInputStream(byteArray);\n        } catch (Exception e) {\n            log.error(\"Failed to convert Base64 string to InputStream\", e);\n            throw new BusinessException(SYSTEM_ERROR);\n        }\n    }\n\n    /**\n     * Compress image\n     *\n     * @param inputStream Original image input stream\n     * @param scale Compression ratio (0.0-1.0)\n     * @return Compressed image input stream\n     */","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java#L12-L48","documentation":"base64ToImageInputStream converts a Base64-encoded image string into an InputStream. It validates the input up-front and throws IllegalArgumentException when the string is null or blank, because decoding an empty value can never produce a valid image stream.","triggerScenarios":"Calling ImageUtil.base64ToImageInputStream(null), an empty string \"\", or a whitespace-only string like \"   \".","commonSituations":"An upload request missing the image field, a frontend sending an empty data attribute, or a data-URL prefix stripped incorrectly leaving an empty payload.","solutions":["Check the Base64 string for null/blank before calling and return a client-friendly validation error","Fix the upstream producer so the image field is always populated when this API is invoked","If a data URL is expected, strip the \"data:image/...;base64,\" prefix and verify the remainder is non-empty"],"exampleFix":"// before\nInputStream in = ImageUtil.base64ToImageInputStream(request.getImageBase64());\n// after\nString b64 = request.getImageBase64();\nif (b64 == null || b64.trim().isEmpty()) {\n    throw new BadRequestException(\"imageBase64 is required\");\n}\nInputStream in = ImageUtil.base64ToImageInputStream(b64);","handlingStrategy":"validation","validationCode":"if (b64 == null || b64.trim().isEmpty()) { throw new BadRequestException(\"imageBase64 is required\"); }","typeGuard":"boolean isValidBase64(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":null,"preventionTips":["Validate required image fields at the API boundary before calling utilities","Make the DTO field @NotBlank so bean validation rejects empty payloads early"],"tags":["java","validation","base64","image"],"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"}