{"record":{"id":"cf6bb5640f2a2bdd","repo":"apache/shenyu","slug":"file-file-does-not-exist","errorCode":null,"errorMessage":"File '\" + file + \"' does not exist","messagePattern":"File '\" \\+ file \\+ \"' does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java","lineNumber":744,"sourceCode":"        }\n\n        /**\n         * file to bytes.\n         *\n         * @param file file\n         * @return byte\n         * @throws IOException IOException\n         */\n        public static byte[] toBytes(final File file) throws IOException {\n            if (file.exists()) {\n                if (file.isDirectory()) {\n                    throw new IOException(\"File '\" + file + \"' exists but is a directory\");\n                }\n                if (!file.canRead()) {\n                    throw new IOException(\"File '\" + file + \"' cannot be read\");\n                }\n            } else {\n                throw new FileNotFoundException(\"File '\" + file + \"' does not exist\");\n            }\n            InputStream input = null;\n            try {\n                input = Files.newInputStream(file.toPath());\n                return toBytes(input);\n            } finally {\n                try {\n                    if (Objects.nonNull(input)) {\n                        input.close();\n                    }\n                } catch (IOException ioe) {\n                    LOG.error(\"toBytes error\", ioe);\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java#L726-L762","documentation":"HttpUtils.toBytes(File) throws FileNotFoundException when the given File does not exist at the time of the call. This is a standard Java FileNotFoundException subclass of IOException carrying the path in the message.","triggerScenarios":"Calling toBytes with a path that is absent: a typo in a configured file path, the file was deleted/moved before the call, or an optional file is dereferenced without an existence check.","commonSituations":"Certificate/keystore paths configured in shenyu-admin pointing to files never created; container volumes not mounted so the expected file is missing; working-directory differences making relative paths resolve incorrectly.","solutions":["Correct the configured path to the actual file location; use absolute paths to avoid CWD surprises.","Verify the file exists with Files.exists(path) before calling, and create/obtain it if this is a first-run setup.","In Docker/K8s, confirm the volume or ConfigMap/Secret mounting the file is present in the container.","Catch FileNotFoundException separately from IOException to give a distinct 'file missing' error message."],"exampleFix":"// before\nbyte[] bytes = HttpUtils.toBytes(new File(\"certs/server.pem\"));\n// after\nPath path = Paths.get(\"/etc/shenyu/certs/server.pem\");\nif (!Files.exists(path)) { throw new IllegalStateException(\"Missing cert file: \" + path); }\nbyte[] bytes = HttpUtils.toBytes(path.toFile());","handlingStrategy":"validation","validationCode":"Path path = file.toPath();\nif (!Files.exists(path)) {\n    throw new FileNotFoundException(\"File does not exist: \" + path.toAbsolutePath());\n}\nif (!Files.isRegularFile(path)) {\n    throw new IllegalArgumentException(\"Not a regular file: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n    byte[] bytes = HttpUtils.toBytes(file);\n} catch (FileNotFoundException e) {\n    log.error(\"Configured file is missing: {}\", file, e);\n    throw new IllegalStateException(\"Missing required file — check path and volume mounts\", e);\n}","preventionTips":["Use absolute paths so the current working directory cannot change resolution.","Verify volume/ConfigMap mounts exist in containers before the app starts.","Log the absolute path (toAbsolutePath()) in errors to expose CWD confusion.","Optionally generate/create default files on first run if they are optional."],"tags":["io","file","filenotfound"],"backgroundTag":"file-not-found","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}