{"record":{"id":"41cd5e6adf2d016e","repo":"apache/hadoop","slug":"file-not-open-for-writing","errorCode":null,"errorMessage":"file not open for writing.","messagePattern":"file not open for writing\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TextWriterImageVisitor.java","lineNumber":99,"sourceCode":"    close();\n  }\n\n  /**\n   * Close output stream and prevent further writing\n   */\n  private void close() throws IOException {\n    fw.close();\n    okToWrite = false;\n  }\n\n  /**\n   * Write parameter to output file (and possibly screen).\n   *\n   * @param toWrite Text to write to file\n   */\n  protected void write(String toWrite) throws IOException  {\n    if(!okToWrite)\n      throw new IOException(\"file not open for writing.\");\n\n    if(printToScreen)\n      System.out.print(toWrite);\n\n    try {\n      fw.write(toWrite);\n    } catch (IOException e) {\n      okToWrite = false;\n      throw e;\n    }\n  }\n}\n","sourceCodeStart":81,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TextWriterImageVisitor.java#L81-L112","documentation":"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.","triggerScenarios":"Calling write() after finish()/close(); a first FileWriter IOException (ENOSPC, closed file) followed by more writes; reusing the visitor after finishAbnormally().","commonSituations":"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.","solutions":["Scan upward in the log for the first IOException on the FileWriter — fix that root cause (free disk space, correct output path, permissions)","Guarantee exactly one finish()/close() per visitor and no writes afterwards","Check `df -h <outputdir>` and write access before rerunning"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  visitor.write(data);\n} catch (IOException e) {\n  if (\"file not open for writing.\".equals(e.getMessage())) {\n    // secondary failure: find the first IOException earlier in the log,\n    // check disk space and output path, then rebuild the visitor from scratch\n    LOG.error(\"visitor closed; original failure precedes this one\", e);\n  }\n  throw e;\n}","preventionTips":["Call finish()/close() exactly once per visitor and never write afterwards","Check output path writability and disk space before starting oiv_legacy","Treat this message as a symptom: always investigate the preceding error"],"tags":["hdfs","oiv-legacy","io","visitor-lifecycle"],"backgroundTag":"write-to-closed-stream","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}