{"record":{"id":"3eba068ceef5c92b","repo":"apache/dubbo","slug":"file-is-null","errorCode":null,"errorMessage":"File is null.","messagePattern":"File is null\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java","lineNumber":229,"sourceCode":"    public static void writeLines(OutputStream os, String[] lines) throws IOException {\n        try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(os))) {\n            for (String line : lines) {\n                writer.println(line);\n            }\n            writer.flush();\n        }\n    }\n\n    /**\n     * write lines.\n     *\n     * @param file  file.\n     * @param lines lines.\n     * @throws IOException If an I/O error occurs\n     */\n    public static void writeLines(File file, String[] lines) throws IOException {\n        if (file == null) {\n            throw new IOException(\"File is null.\");\n        }\n        writeLines(new FileOutputStream(file), lines);\n    }\n\n    /**\n     * append lines.\n     *\n     * @param file  file.\n     * @param lines lines.\n     * @throws IOException If an I/O error occurs\n     */\n    public static void appendLines(File file, String[] lines) throws IOException {\n        if (file == null) {\n            throw new IOException(\"File is null.\");\n        }\n        writeLines(new FileOutputStream(file, true), lines);\n    }\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java#L211-L247","documentation":"IOUtils.writeLines(File, String[]) rejects a null File argument immediately with IOException before attempting to open a FileOutputStream. It is a fail-fast null guard, not an I/O failure.","triggerScenarios":"Calling IOUtils.writeLines(file, lines) where the file variable resolved to null (e.g. a config path that was never set, a method parameter defaulted to null).","commonSituations":"Uninitialized file paths from configuration; a previous step that was supposed to compute a path but returned null silently; refactoring that dropped the path assignment.","solutions":["Ensure the File argument is non-null by computing/validating the path before calling writeLines","Guard with an explicit null check that supplies a sensible default or fails with a clearer message upstream","Log the intended path early so a null is obvious in the stack trace"],"exampleFix":"// before\nIOUtils.writeLines(configFile, lines);\n// after\njava.util.Objects.requireNonNull(configFile, \"configFile path\");\nIOUtils.writeLines(configFile, lines);","handlingStrategy":"validation","validationCode":"java.util.Objects.requireNonNull(file, \"output file\");\nIOUtils.writeLines(file, lines);","typeGuard":"static boolean isWritableFile(File f) { return f != null; }","tryCatchPattern":"try { IOUtils.writeLines(file, lines); }\ncatch (java.io.IOException e) { /* file was null or unwritable */ }","preventionTips":["Validate file paths at config-load time","Centralize file-path resolution so nulls surface early"],"tags":["io","file","null-check"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}