{"record":{"id":"dc1ccf1114cc493f","repo":"chinabugotech/hutool","slug":"file-path-is-blank","errorCode":null,"errorMessage":"File path is blank!","messagePattern":"File path is blank!","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java","lineNumber":318,"sourceCode":"\t * @param path   文件路径\n\t * @return File\n\t */\n\tpublic static File file(String parent, String path) {\n\t\treturn file(new File(parent), path);\n\t}\n\n\t/**\n\t * 创建File对象<br>\n\t * 根据的路径构建文件，在Win下直接构建，在Linux下拆分路径单独构建\n\t * 此方法会检查slip漏洞，漏洞说明见http://blog.nsfocus.net/zip-slip-2/\n\t *\n\t * @param parent 父文件对象\n\t * @param path   文件路径\n\t * @return File\n\t */\n\tpublic static File file(File parent, String path) {\n\t\tif (StrUtil.isBlank(path)) {\n\t\t\tthrow new NullPointerException(\"File path is blank!\");\n\t\t}\n\t\treturn checkSlip(parent, buildFile(parent, path));\n\t}\n\n\t/**\n\t * 通过多层目录参数创建文件<br>\n\t * 此方法会检查slip漏洞，漏洞说明见http://blog.nsfocus.net/zip-slip-2/\n\t *\n\t * @param directory 父目录\n\t * @param names     元素名（多层目录名），由外到内依次传入\n\t * @return the file 文件\n\t * @since 4.0.6\n\t */\n\tpublic static File file(File directory, String... names) {\n\t\tAssert.notNull(directory, \"directory must not be null\");\n\t\tif (ArrayUtil.isEmpty(names)) {\n\t\t\treturn directory;\n\t\t}","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java#L300-L336","documentation":"FileUtil.file(File parent, String path) builds a File under a parent and applies a zip-slip security check. If path is null, empty, or whitespace-only it throws NullPointerException(\"File path is blank!\"). Note the library deliberately uses NPE rather than IllegalArgumentException for a blank string argument.","triggerScenarios":"Calling FileUtil.file(parent, path) where path is null, \"\", or contains only whitespace.","commonSituations":"Building paths from missing config keys; splitting a path into segments where one segment is empty; a Map.get/getOrDefault returning null that is passed straight through.","solutions":["Validate with StrUtil.isNotBlank(path) before calling file().","Provide a sensible default or fail early with your own error when the path source is empty.","Sanitize path segments from split operations to drop blanks."],"exampleFix":"// before\nFile f = FileUtil.file(parent, name); // NPE if name is blank\n\n// after\nif (StrUtil.isBlank(name)) {\n    throw new IllegalArgumentException(\"name required\");\n}\nFile f = FileUtil.file(parent, name);","handlingStrategy":"validation","validationCode":"if (StrUtil.isBlank(path)) {\n    throw new IllegalArgumentException(\"path must not be blank\");\n}\nFile f = FileUtil.file(parent, path);","typeGuard":"static boolean isUsablePath(String path) {\n    return path != null && !path.trim().isEmpty();\n}","tryCatchPattern":"try {\n    return FileUtil.file(parent, path);\n} catch (NullPointerException e) {\n    // blank path: provide a clear error with the parent context\n}","preventionTips":["Validate with StrUtil.isNotBlank(path) before constructing files.","Drop empty segments produced by String.split before joining.","Provide defaults for missing config keys rather than passing blanks through."],"tags":["io","file","validation","null-safety"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}