iflytek/astron-agent · warning · IllegalArgumentException
Base64 string cannot be empty
Error message
Base64 string cannot be empty
What it means
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.
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
Example fix
// before
InputStream in = ImageUtil.base64ToImageInputStream(request.getImageBase64());
// after
String b64 = request.getImageBase64();
if (b64 == null || b64.trim().isEmpty()) {
throw new BadRequestException("imageBase64 is required");
}
InputStream in = ImageUtil.base64ToImageInputStream(b64); Defensive patterns
Strategy: validation
Validate before calling
if (b64 == null || b64.trim().isEmpty()) { throw new BadRequestException("imageBase64 is required"); } Type guard
boolean isValidBase64(String s) { return s != null && !s.trim().isEmpty(); } Prevention
- Validate required image fields at the API boundary before calling utilities
- Make the DTO field @NotBlank so bean validation rejects empty payloads early
When it happens
Trigger: Calling ImageUtil.base64ToImageInputStream(null), an empty string "", or a whitespace-only string like " ".
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- 99999
- Input stream cannot be empty
- Compression ratio must be between 0-1
- User UID cannot be null
- DUPLICATE_BOT_NAME
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/691329e2c2313552.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java:30
import static com.iflytek.astron.console.commons.constant.ResponseEnum.SYSTEM_ERROR;
/**
* Image processing utility class
*
*/
@Slf4j
public class ImageUtil {
/**
* Convert base64 string to InputStream
*
* @param base64String Base64 encoded image string
* @return InputStream object
*/
public static InputStream base64ToImageInputStream(String base64String) {
if (base64String == null || base64String.trim().isEmpty()) {
throw new IllegalArgumentException("Base64 string cannot be empty");
}
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
*/View on GitHub (pinned to 5e758547a8)