{"record":{"id":"db38c753f5cb79a0","repo":"iflytek/astron-agent","slug":"unsupported-image-size-using-default-size","errorCode":null,"errorMessage":"Unsupported image size: {}, using default size: {}","messagePattern":"Unsupported image size: (.+?), using default size: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java","lineNumber":434,"sourceCode":"            RoleContent roleContent = new RoleContent(\"user\", question);\n            text.add(JSON.toJSON(roleContent));\n            message.put(\"text\", text);\n            payload.put(\"message\", message);\n            requestJson.put(\"payload\", payload);\n\n            return requestJson;\n        }\n    }\n\n    /**\n     * Validate image size\n     */\n    private int validateImageSize(Integer size) {\n        if (size == null) {\n            return DEFAULT_IMAGE_SIZE;\n        }\n        if (!ALLOWED_IMAGE_SIZES.contains(size)) {\n            log.warn(\"Unsupported image size: {}, using default size: {}\", size, DEFAULT_IMAGE_SIZE);\n            return DEFAULT_IMAGE_SIZE;\n        }\n        return size;\n    }\n\n    /**\n     * Build image generation request data\n     */\n    private JSONObject buildImageGenerationRequest(String imageAppId, String uid, String prompt, int size) {\n        JSONObject request = new JSONObject();\n\n        // Build header\n        JSONObject header = new JSONObject();\n        header.put(\"app_id\", imageAppId);\n        header.put(\"uid\", uid);\n        request.put(\"header\", header);\n\n        // Build parameter","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java#L416-L452","documentation":"validateImageSize checks the requested image dimension against ALLOWED_IMAGE_SIZES before calling the BotAI image API. A null size silently becomes DEFAULT_IMAGE_SIZE; a non-null but unsupported value logs this warning naming both the rejected size and the default, then returns DEFAULT_IMAGE_SIZE. The API call proceeds with the default rather than failing.","triggerScenarios":"imageSize() is invoked with size values outside ALLOWED_IMAGE_SIZES — frontend sends a pixel value the backend whitelist doesn't include (e.g. 768 vs allowed {256,512,1024}), a client sends size as a different unit, or an older client sends a removed option.","commonSituations":"Frontend/backend whitelist drift after adding new size options; clients hardcoding sizes not in the allowed set; users selecting 'custom' sizes in UI; API consumers passing string-parsed values that map to odd integers.","solutions":["Add the requested size to ALLOWED_IMAGE_SIZES if it is genuinely supported by the BotAI image API","Snap unsupported sizes to the nearest allowed value instead of always defaulting to smallest/largest","Validate size in the frontend/controller against the same whitelist and reject early with a clear message","Keep the clamp behavior if acceptable; log at info rather than warn to reduce noise"],"exampleFix":"// before\nif (!ALLOWED_IMAGE_SIZES.contains(size)) {\n    log.warn(\"Unsupported image size: {}, using default size: {}\", size, DEFAULT_IMAGE_SIZE);\n    return DEFAULT_IMAGE_SIZE;\n}\n// after\nif (!ALLOWED_IMAGE_SIZES.contains(size)) {\n    int nearest = ALLOWED_IMAGE_SIZES.stream()\n        .min(Comparator.comparingInt(s -> Math.abs(s - size)))\n        .orElse(DEFAULT_IMAGE_SIZE);\n    log.warn(\"Unsupported image size: {}, snapping to {}\", size, nearest);\n    return nearest;\n}","handlingStrategy":"validation","validationCode":"// validate on the caller side before requesting an image\nSet<Integer> ALLOWED = Set.of(256, 512, 1024);\nif (requestedSize != null && !ALLOWED.contains(requestedSize)) {\n    throw new IllegalArgumentException(\"size must be one of \" + ALLOWED);\n}","typeGuard":"boolean isAllowedImageSize(Integer size) {\n    return size != null && ALLOWED_IMAGE_SIZES.contains(size);\n}","tryCatchPattern":"int size = client.validateImageSize(requestedSize);\nif (size != requestedSize && requestedSize != null) {\n    log.info(\"Requested size {} was clamped to {}\", requestedSize, size);\n}","preventionTips":["Publish the allowed size whitelist to frontend teams and enforce it in UI dropdowns","Share the whitelist via a common constants module or config so client/server never drift","Normalize size units (px) across client and server","Add a contract test asserting frontend size options are a subset of ALLOWED_IMAGE_SIZES"],"tags":["java","validation","image-generation","parameter-clamping"],"backgroundTag":"invalid-argument-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}