{"record":{"id":"33b618e49f29f6c4","repo":"spring-projects/spring-ai","slug":"unsupported-image-data-type","errorCode":null,"errorMessage":"Unsupported image data type: ","messagePattern":"Unsupported image data type: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/VertexAiEmbeddingUtils.java","lineNumber":271,"sourceCode":"\t\tpublic MimeType mimeType;\n\n\t\tpublic static ImageBuilder of(MimeType mimeType) {\n\t\t\tAssert.notNull(mimeType, \"MimeType must not be null\");\n\t\t\tvar builder = new ImageBuilder();\n\t\t\tbuilder.mimeType = mimeType;\n\t\t\treturn builder;\n\t\t}\n\n\t\tpublic ImageBuilder imageData(Object imageData) {\n\t\t\tAssert.notNull(imageData, \"Image data must not be null\");\n\t\t\tif (imageData instanceof byte[] bytes) {\n\t\t\t\treturn imageBytes(bytes);\n\t\t\t}\n\t\t\telse if (imageData instanceof String uri) {\n\t\t\t\treturn gcsUri(uri);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported image data type: \" + imageData.getClass());\n\t\t\t}\n\t\t}\n\n\t\tpublic ImageBuilder imageBytes(byte[] imageBytes) {\n\t\t\tAssert.notNull(imageBytes, \"Image bytes must not be null\");\n\t\t\tthis.imageBytes = imageBytes;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic ImageBuilder gcsUri(String gcsUri) {\n\t\t\tAssert.hasText(gcsUri, \"GCS URI must not be empty\");\n\t\t\tthis.gcsUri = gcsUri;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Struct build() {\n\n\t\t\tStruct.Builder imageBuilder = Struct.newBuilder();","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/VertexAiEmbeddingUtils.java#L253-L289","documentation":"VertexAiEmbeddingUtils.ImageBuilder.imageData(Object) accepts only byte[] (raw image bytes) or String (a GCS URI, gs://...). Any other type falls through to IllegalArgumentException(\"Unsupported image data type: \" + imageData.getClass()), telling you which class was supplied so you can convert it.","triggerScenarios":"Calling image.imageData(...) with a type other than byte[] or String — e.g. java.io.File, BufferedImage, InputStream, Path, or a byte[]-like wrapper.","commonSituations":"Passing a java.io.File or BufferedImage directly from image-processing code; passing a URI/URL object instead of the gs:// string; loading images with ImageIO and forgetting to encode to bytes.","solutions":["Convert the object to byte[] (read file bytes or encode the BufferedImage) and pass imageBytes(...).","If the image lives in Google Cloud Storage, pass its gs:// URI as a String.","Check the reported class name in the message to identify exactly which type slipped through."],"exampleFix":"// before\nimage.imageData(new File(\"cat.jpg\"));\n// after\nimage.imageData(Files.readAllBytes(Path.of(\"cat.jpg\")));","handlingStrategy":"type-guard","validationCode":"if (!(data instanceof byte[]) && !(data instanceof String)) {\n    throw new IllegalArgumentException(\"imageData must be byte[] or String GCS URI, got \" + data.getClass());\n}","typeGuard":"static boolean isSupportedImageData(Object o) {\n    return o instanceof byte[] || (o instanceof String s && s.startsWith(\"gs://\"));\n}","tryCatchPattern":null,"preventionTips":["Convert File/BufferedImage to byte[] before passing image data.","Pass GCS references as gs:// Strings, not URI/URL objects.","Centralize image conversion in one helper used by all call sites."],"tags":["vertex-ai","image","type-mismatch","invalid-argument"],"backgroundTag":"type-mismatch","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}