{"record":{"id":"ef1f97d49c505dab","repo":"chinabugotech/hutool","slug":"image-type-of-file-is-not-supported","errorCode":null,"errorMessage":"Image type of file [{}] is not supported!","messagePattern":"Image type of file \\[(.+?)\\] is not supported!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java","lineNumber":1951,"sourceCode":"\t}\n\n\t/**\n\t * 从文件中读取图片\n\t *\n\t * @param imageFile 图片文件\n\t * @return 图片\n\t * @since 3.2.2\n\t */\n\tpublic static BufferedImage read(File imageFile) {\n\t\tBufferedImage result;\n\t\ttry {\n\t\t\tresult = ImageIO.read(imageFile);\n\t\t} catch (IOException e) {\n\t\t\tthrow new IORuntimeException(e);\n\t\t}\n\n\t\tif (null == result) {\n\t\t\tthrow new IllegalArgumentException(\"Image type of file [\" + imageFile.getName() + \"] is not supported!\");\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * 从URL中获取或读取图片对象\n\t *\n\t * @param url URL\n\t * @return {@link Image}\n\t * @since 5.5.8\n\t */\n\tpublic static Image getImage(URL url) {\n\t\treturn Toolkit.getDefaultToolkit().getImage(url);\n\t}\n\n\t/**\n\t * 从{@link Resource}中读取图片","sourceCodeStart":1933,"sourceCodeEnd":1969,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java#L1933-L1969","documentation":"ImgUtil.read(File) delegates to javax.imageio.ImageIO.read, which returns null when no registered ImageReader can decode the file (unknown/unsupported format or corrupted content). Hutool converts that null into IllegalArgumentException naming the file.","triggerScenarios":"Reading a file that is not a decodable image (e.g. SVG, HEIC, AVIF, a text file, a truncated/corrupted JPG/PNG). ImageIO has no reader for that format on the classpath.","commonSituations":"Unsupported modern formats (WEBP/AVIF/HEIC need extra readers); files with wrong extension; partially downloaded/corrupt images; minimal JRE without the image plugins.","solutions":["Verify the file is a supported format (PNG/JPG/GIF/BMP) using FileTypeUtil before reading.","Add the required ImageIO reader plugin (e.g. webp-imageio, TwelveMonkeys ImageIO) for advanced formats.","Re-download/re-encode the source if it is corrupt."],"exampleFix":"// before\nBufferedImage img = ImgUtil.read(new File(\"logo.svg\"));\n// after - use a supported raster format, or add an SVG/extra reader\nBufferedImage img = ImgUtil.read(new File(\"logo.png\"));","handlingStrategy":"validation","validationCode":"void requireReadableImage(File f){ String[] ok = {\"jpg\",\"png\",\"gif\",\"bmp\"}; if(!ArrayUtil.contains(ok, FileTypeUtil.getType(f))) throw new IllegalArgumentException(\"not a decodable image: \"+f); }","typeGuard":"boolean isDecodableImageFile(File f){ return f!=null && f.exists() && ArrayUtil.contains(new String[]{\"jpg\",\"png\",\"gif\",\"bmp\"}, FileTypeUtil.getType(f)); }","tryCatchPattern":"try { img = ImgUtil.read(file); }\ncatch (IllegalArgumentException e){ if(e.getMessage().contains(\"not supported\")) { /* convert / add reader */ } else throw e; }","preventionTips":["Whitelist image types via FileTypeUtil before read.","Add TwelveMonkeys ImageIO for WEBP/AVIF/TIFF/SVG.","Reject non-image uploads at the boundary."],"tags":["image","imageio","format","io","argument"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}