{"record":{"id":"32ec3c0c3a2a2224","repo":"iflytek/astron-agent","slug":"input-stream-cannot-be-empty","errorCode":null,"errorMessage":"Input stream cannot be empty","messagePattern":"Input stream 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":51,"sourceCode":"        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     */\n    public static InputStream compressImage(InputStream inputStream, float scale) {\n        if (inputStream == null) {\n            throw new IllegalArgumentException(\"Input stream cannot be empty\");\n        }\n        if (scale <= 0 || scale > 1) {\n            throw new IllegalArgumentException(\"Compression ratio must be between 0-1\");\n        }\n\n        ByteArrayOutputStream outputStream = null;\n        try {\n            outputStream = new ByteArrayOutputStream();\n            ImgUtil.scale(inputStream, outputStream, scale);\n            return new ByteArrayInputStream(outputStream.toByteArray());\n        } catch (Exception e) {\n            log.error(\"Image compression failed, scale: {}\", scale, e);\n            throw new BusinessException(SYSTEM_ERROR);\n        } finally {\n            IoUtil.close(inputStream);\n            IoUtil.close(outputStream);\n        }\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java#L33-L69","documentation":"Guard in ImageUtil.compressImage: the supplied InputStream is null, so compression cannot proceed and this error is raised. It is a sentinel validation on the image-compression entry point, commonly hit when an upstream Base64 decode or upload step produced no stream.","triggerScenarios":"Calling ImageUtil.compressImage(null, scale), often because an earlier base64ToImageInputStream or file-open step failed and its null result was passed through unchecked.","commonSituations":"An optional upload field was absent so the stream was never created, a helper returns null on error instead of throwing, or refactoring changed the call order so the stream is read/closed before compression.","solutions":["Ensure the InputStream is created successfully before calling compressImage; fail earlier if the source is missing","If compressing a base64 payload, call base64ToImageInputStream first and check for exceptions rather than letting a null propagate"],"exampleFix":"// before\nInputStream compressed = ImageUtil.compressImage(maybeNullStream, 0.5f);\n// after\nif (maybeNullStream == null) {\n    throw new BadRequestException(\"image stream is required\");\n}\nInputStream compressed = ImageUtil.compressImage(maybeNullStream, 0.5f);","handlingStrategy":"validation","validationCode":"if (in == null) { throw new BadRequestException(\"image stream is required\"); }","typeGuard":"boolean hasStream(InputStream s) { return s != null; }","tryCatchPattern":null,"preventionTips":["Avoid helpers that return null streams on failure; prefer throwing","Check construction results before passing them on"],"tags":["java","null","image","validation"],"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"}