{"record":{"id":"1b97ee78280a769e","repo":"chinabugotech/hutool","slug":"image-type-of-is-not-supported","errorCode":null,"errorMessage":"Image type of [{}] is not supported!","messagePattern":"Image type of \\[(.+?)\\] is not supported!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java","lineNumber":2039,"sourceCode":"\t}\n\n\t/**\n\t * 从URL中读取图片\n\t *\n\t * @param imageUrl 图片文件\n\t * @return 图片\n\t * @since 3.2.2\n\t */\n\tpublic static BufferedImage read(URL imageUrl) {\n\t\tBufferedImage result;\n\t\ttry {\n\t\t\tresult = ImageIO.read(imageUrl);\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 [\" + imageUrl + \"] is not supported!\");\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * 获取{@link ImageOutputStream}\n\t *\n\t * @param out {@link OutputStream}\n\t * @return {@link ImageOutputStream}\n\t * @throws IORuntimeException IO异常\n\t * @since 3.1.2\n\t */\n\tpublic static ImageOutputStream getImageOutputStream(OutputStream out) throws IORuntimeException {\n\t\tImageOutputStream result;\n\t\ttry {\n\t\t\tresult = ImageIO.createImageOutputStream(out);\n\t\t} catch (IOException e) {","sourceCodeStart":2021,"sourceCodeEnd":2057,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java#L2021-L2057","documentation":"ImgUtil.read(URL) wraps ImageIO.read(URL); when no reader decodes the URL content it returns null, and Hutool raises IllegalArgumentException naming the URL ('Image type of [{}] is not supported!').","triggerScenarios":"Reading an image from a URL whose content is not a baseline-decodable image (SVG/AVIF/HEIC), returns an HTML error page, or a content-type the JVM cannot decode; network/redirect issues yielding non-image bytes.","commonSituations":"Fetching avatars/icons that are SVG; URLs that 404 and return text; content negotiation returning WEBP without a reader; CDN redirects not producing image bytes.","solutions":["Download the bytes, verify content-type/magic bytes, then read via ImgUtil.read(InputStream) with a confirmed format.","Install ImageIO plugins for the content type you expect (WEBP/AVIF/HEIC).","Check HTTP status and content-type before attempting to decode."],"exampleFix":"// before\nBufferedImage img = ImgUtil.read(new URL(\"https://example.com/icon.svg\"));\n// after - fetch and verify\nbyte[] b = HttpUtil.downloadBytes(\"https://example.com/icon.png\");\nBufferedImage img = ImgUtil.read(IoUtil.toStream(b));","handlingStrategy":"validation","validationCode":"void requireImageUrl(URL u) throws IOException { HttpURLConnection c=(HttpURLConnection)u.openConnection(); c.setRequestMethod(\"HEAD\"); String ct=c.getContentType(); if(ct==null || !ct.startsWith(\"image/\")) throw new IllegalArgumentException(\"URL is not an image: \"+ct); }","typeGuard":"boolean isImageUrl(URL u) throws IOException { HttpURLConnection c=(HttpURLConnection)u.openConnection(); c.setRequestMethod(\"HEAD\"); String ct=c.getContentType(); return ct!=null && ct.startsWith(\"image/\"); }","tryCatchPattern":"try { img = ImgUtil.read(url); }\ncatch (IllegalArgumentException e){ if(e.getMessage().contains(\"not supported\")) { byte[] b=HttpUtil.downloadBytes(url.toString()); img=ImgUtil.read(IoUtil.toStream(b)); } else throw e; }","preventionTips":["Verify HTTP status and content-type before decoding URLs.","Download to bytes first so you can inspect magic bytes.","Install ImageIO plugins for modern formats you expect."],"tags":["image","imageio","format","network","url","argument"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}