iflytek/astron-agent · warning · IllegalArgumentException
Input stream cannot be empty
Error message
Input stream cannot be empty
What it means
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.
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
Example fix
// before
InputStream compressed = ImageUtil.compressImage(maybeNullStream, 0.5f);
// after
if (maybeNullStream == null) {
throw new BadRequestException("image stream is required");
}
InputStream compressed = ImageUtil.compressImage(maybeNullStream, 0.5f); Defensive patterns
Strategy: validation
Validate before calling
if (in == null) { throw new BadRequestException("image stream is required"); } Type guard
boolean hasStream(InputStream s) { return s != null; } Prevention
- Avoid helpers that return null streams on failure; prefer throwing
- Check construction results before passing them on
When it happens
Trigger: Calling ImageUtil.compressImage(null, scale), often because an earlier base64ToImageInputStream or file-open step failed and its null result was passed through unchecked.
Common situations: 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.
Related errors
- User UID cannot be null
- Base64 string cannot be empty
- Compression ratio must be between 0-1
- PARAM_ERROR
- DUPLICATE_BOT_NAME
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/32ec3c0c3a2a2224.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java:51
try {
byte[] byteArray = Base64.getDecoder().decode(base64String);
return new ByteArrayInputStream(byteArray);
} catch (Exception e) {
log.error("Failed to convert Base64 string to InputStream", e);
throw new BusinessException(SYSTEM_ERROR);
}
}
/**
* Compress image
*
* @param inputStream Original image input stream
* @param scale Compression ratio (0.0-1.0)
* @return Compressed image input stream
*/
public static InputStream compressImage(InputStream inputStream, float scale) {
if (inputStream == null) {
throw new IllegalArgumentException("Input stream cannot be empty");
}
if (scale <= 0 || scale > 1) {
throw new IllegalArgumentException("Compression ratio must be between 0-1");
}
ByteArrayOutputStream outputStream = null;
try {
outputStream = new ByteArrayOutputStream();
ImgUtil.scale(inputStream, outputStream, scale);
return new ByteArrayInputStream(outputStream.toByteArray());
} catch (Exception e) {
log.error("Image compression failed, scale: {}", scale, e);
throw new BusinessException(SYSTEM_ERROR);
} finally {
IoUtil.close(inputStream);
IoUtil.close(outputStream);
}
}View on GitHub (pinned to 5e758547a8)