{"record":{"id":"e0f80c75b5a8b9d9","repo":"apache/hadoop","slug":"unknown-mode-mode","errorCode":null,"errorMessage":"Unknown mode: ${mode}","messagePattern":"Unknown mode: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/EventWriter.java","lineNumber":79,"sourceCode":"   * avro encoding format supported by EventWriter.\n   */\n  public enum WriteMode { JSON, BINARY }\n  private final WriteMode writeMode;\n  private final boolean jsonOutput;  // Cache value while we have 2 modes\n\n  @VisibleForTesting\n  public EventWriter(FSDataOutputStream out, WriteMode mode)\n      throws IOException {\n    this.out = out;\n    this.writeMode = mode;\n    if (this.writeMode==WriteMode.JSON) {\n      this.jsonOutput = true;\n      out.writeBytes(VERSION);\n    } else if (this.writeMode==WriteMode.BINARY) {\n      this.jsonOutput = false;\n      out.writeBytes(VERSION_BINARY);\n    } else {\n      throw new IOException(\"Unknown mode: \" + mode);\n    }\n    out.writeBytes(\"\\n\");\n    out.writeBytes(Event.SCHEMA$.toString());\n    out.writeBytes(\"\\n\");\n    if (!this.jsonOutput) {\n      this.encoder = EncoderFactory.get().binaryEncoder(out, null);\n    } else {\n      this.encoder = EncoderFactory.get().jsonEncoder(Event.SCHEMA$, out);\n    }\n  }\n  \n  synchronized void write(HistoryEvent event) throws IOException { \n    Event wrapper = new Event();\n    wrapper.setType(event.getEventType());\n    wrapper.setEvent(event.getDatum());\n    writer.write(wrapper, encoder);\n    if (this.jsonOutput) {\n      encoder.flush();","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/EventWriter.java#L61-L97","documentation":"EventWriter(FSDataOutputStream, WriteMode) supports exactly two modes: WriteMode.JSON (writes \"Avro-Json\" header, JSON encoder) and WriteMode.BINARY (\"Avro-Binary\", binary encoder). Any other value - including null - throws IOException(\"Unknown mode\"). With the stock two-value WriteMode enum this is a defensive guard for future/forked modes; via the public API it is only reachable by passing null.","triggerScenarios":"Passing a null WriteMode (uninitialized field, broken config plumbing) to the EventWriter constructor; or, in a fork, adding a WriteMode constant without updating this constructor.","commonSituations":"Bugs where the mode variable is never assigned; forked Hadoop adding e.g. XML mode; tests constructing EventWriter directly with default/null mode.","solutions":["Always pass WriteMode.JSON or WriteMode.BINARY explicitly (JobHistory normally selects this for you).","Null-check the mode before constructing the writer.","In forks, wire every new WriteMode constant to a header string and encoder in this constructor before shipping."],"exampleFix":"// before\nEventWriter writer = new EventWriter(out, mode); // mode null -> Unknown mode: null\n\n// after\nWriteMode effective = (mode != null) ? mode : WriteMode.JSON;\nEventWriter writer = new EventWriter(out, effective);","handlingStrategy":"validation","validationCode":"if (mode != EventWriter.WriteMode.JSON && mode != EventWriter.WriteMode.BINARY) {\n  throw new IllegalArgumentException(\"mode must be JSON or BINARY, got: \" + mode);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never leave the WriteMode variable unset; default it explicitly.","In forks, pair every new WriteMode constant with header/encoder handling here."],"tags":["hadoop","mapreduce","jobhistory","enum","ioexception","defensive"],"backgroundTag":"invalid-enum-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}