apache/hadoop · error · IOException

file not open for writing.

Error message

file not open for writing.

What it means

TextWriterImageVisitor flips okToWrite to false after close() and after any IOException from the underlying FileWriter; any later write() then throws this generic error. It is almost always a secondary symptom: the primary failure (disk full, stream closed, double finish) happened one step earlier in the log.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TextWriterImageVisitor.java:99

    close();
  }

  /**
   * Close output stream and prevent further writing
   */
  private void close() throws IOException {
    fw.close();
    okToWrite = false;
  }

  /**
   * Write parameter to output file (and possibly screen).
   *
   * @param toWrite Text to write to file
   */
  protected void write(String toWrite) throws IOException  {
    if(!okToWrite)
      throw new IOException("file not open for writing.");

    if(printToScreen)
      System.out.print(toWrite);

    try {
      fw.write(toWrite);
    } catch (IOException e) {
      okToWrite = false;
      throw e;
    }
  }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Scan upward in the log for the first IOException on the FileWriter — fix that root cause (free disk space, correct output path, permissions)
  2. Guarantee exactly one finish()/close() per visitor and no writes afterwards
  3. Check `df -h <outputdir>` and write access before rerunning
Defensive patterns

Strategy: try-catch

Try / catch

try {
  visitor.write(data);
} catch (IOException e) {
  if ("file not open for writing.".equals(e.getMessage())) {
    // secondary failure: find the first IOException earlier in the log,
    // check disk space and output path, then rebuild the visitor from scratch
    LOG.error("visitor closed; original failure precedes this one", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling write() after finish()/close(); a first FileWriter IOException (ENOSPC, closed file) followed by more writes; reusing the visitor after finishAbnormally().

Common situations: oiv_legacy output to a full disk or unwritable path; custom ImageVisitor wrappers calling finish() twice; pipelines that keep feeding a visitor after an error.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/41cd5e6adf2d016e. Report an issue: GitHub.