apache/dubbo · error · IOException

File is null.

Error message

File is null.

What it means

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.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java:229

    public static void writeLines(OutputStream os, String[] lines) throws IOException {
        try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(os))) {
            for (String line : lines) {
                writer.println(line);
            }
            writer.flush();
        }
    }

    /**
     * write lines.
     *
     * @param file  file.
     * @param lines lines.
     * @throws IOException If an I/O error occurs
     */
    public static void writeLines(File file, String[] lines) throws IOException {
        if (file == null) {
            throw new IOException("File is null.");
        }
        writeLines(new FileOutputStream(file), lines);
    }

    /**
     * append lines.
     *
     * @param file  file.
     * @param lines lines.
     * @throws IOException If an I/O error occurs
     */
    public static void appendLines(File file, String[] lines) throws IOException {
        if (file == null) {
            throw new IOException("File is null.");
        }
        writeLines(new FileOutputStream(file, true), lines);
    }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Ensure the File argument is non-null by computing/validating the path before calling writeLines
  2. Guard with an explicit null check that supplies a sensible default or fails with a clearer message upstream
  3. Log the intended path early so a null is obvious in the stack trace

Example fix

// before
IOUtils.writeLines(configFile, lines);
// after
java.util.Objects.requireNonNull(configFile, "configFile path");
IOUtils.writeLines(configFile, lines);
Defensive patterns

Strategy: validation

Validate before calling

java.util.Objects.requireNonNull(file, "output file");
IOUtils.writeLines(file, lines);

Type guard

static boolean isWritableFile(File f) { return f != null; }

Try / catch

try { IOUtils.writeLines(file, lines); }
catch (java.io.IOException e) { /* file was null or unwritable */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/3eba068ceef5c92b. Report an issue: GitHub.