{"record":{"id":"c6b1b7e28819e7da","repo":"chinabugotech/hutool","slug":"error-c6b1b7","errorCode":null,"errorMessage":"给定文件为空","messagePattern":"给定文件为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/img/BackgroundRemoval.java","lineNumber":344,"sourceCode":"\t\t\treturn ImgUtil.toHex(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]),\n\t\t\t\t\tInteger.parseInt(strings[2]));\n\t\t}\n\t\treturn StrUtil.EMPTY;\n\t}\n\n\t// -------------------------------------------------------------------------- private\n\n\t/**\n\t * 文件类型验证\n\t * 根据给定文件类型数据，验证给定文件类型.\n\t *\n\t * @param input      需要进行验证的文件\n\t * @param imagesType 文件包含的类型数组\n\t * @return 返回布尔值 false:给定文件的文件类型在文件数组中  true:给定文件的文件类型 不在给定数组中。\n\t */\n\tprivate static boolean fileTypeValidation(File input, String[] imagesType) {\n\t\tif (!input.exists()) {\n\t\t\tthrow new IllegalArgumentException(\"给定文件为空\");\n\t\t}\n\t\t// 获取图片类型\n\t\tString type = FileTypeUtil.getType(input);\n\t\t// 类型对比\n\t\tif (!ArrayUtil.contains(imagesType, type)) {\n\t\t\tthrow new IllegalArgumentException(StrUtil.format(\"文件类型{}不支持\", type));\n\t\t}\n\t\treturn false;\n\t}\n}\n","sourceCodeStart":326,"sourceCodeEnd":355,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/img/BackgroundRemoval.java#L326-L355","documentation":"BackgroundRemoval.fileTypeValidation throws IllegalArgumentException ('给定文件为空' = 'the given file is empty/missing') when the File passed to it does not exist (input.exists() is false). Despite the word 'empty', the actual condition is non-existence.","triggerScenarios":"Calling a background-removal method with a File whose path does not exist, points to a deleted/moved file, or has a typo in the path.","commonSituations":"User-uploaded file already cleaned up; path from config that is wrong; file on a network mount that is unavailable; relative path resolved against the wrong working directory.","solutions":["Verify input.exists() && input.isFile() before calling the removal method.","Resolve paths to absolute and log them to catch typos / wrong working directory.","Ensure the file is present (re-download, recreate) before processing."],"exampleFix":"// before\nBackgroundRemoval.removeBg(new File(\"/tmp/missing.png\"), ...);\n// after\nFile f = new File(\"/tmp/missing.png\");\nif (!f.isFile()) throw new FileNotFoundException(f.getAbsolutePath());\nBackgroundRemoval.removeBg(f, ...);","handlingStrategy":"validation","validationCode":"void requireExistingImage(File f){ if(f==null || !f.exists() || !f.isFile()) throw new FileNotFoundException(String.valueOf(f)); }","typeGuard":"boolean isReadableFile(File f){ return f != null && f.exists() && f.isFile() && f.canRead(); }","tryCatchPattern":"try { BackgroundRemoval.removeBg(file, ...); }\ncatch (IllegalArgumentException e){ if(e.getMessage().contains(\"给定文件为空\")) { /* report missing path */ } else throw e; }","preventionTips":["Check exists()/isFile() before any file-based image call.","Log absolute paths to catch working-directory issues.","Stream files to stable, verified locations before processing."],"tags":["image","file","argument","background-removal"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}