{"record":{"id":"4d64e606eda39c79","repo":"apache/hadoop","slug":"unexpected-event-type-wrapper-gettype","errorCode":null,"errorMessage":"unexpected event type: ${wrapper.getType()}","messagePattern":"unexpected event type: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/EventReader.java","lineNumber":170,"sourceCode":"      result = new TaskAttemptStartedEvent(); break;\n    case SETUP_ATTEMPT_FINISHED:\n      result = new TaskAttemptFinishedEvent(); break;\n    case SETUP_ATTEMPT_FAILED:\n      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;\n    case SETUP_ATTEMPT_KILLED:\n      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;\n    case CLEANUP_ATTEMPT_STARTED:\n      result = new TaskAttemptStartedEvent(); break;\n    case CLEANUP_ATTEMPT_FINISHED:\n      result = new TaskAttemptFinishedEvent(); break;\n    case CLEANUP_ATTEMPT_FAILED:\n      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;\n    case CLEANUP_ATTEMPT_KILLED:\n      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;\n    case AM_STARTED:\n      result = new AMStartedEvent(); break;\n    default:\n      throw new RuntimeException(\"unexpected event type: \" + wrapper.getType());\n    }\n    result.setDatum(wrapper.getEvent());\n    return result;\n  }\n\n  /**\n   * Close the Event reader\n   * @throws IOException\n   */\n  @Override\n  public void close() throws IOException {\n    if (in != null) {\n      in.close();\n    }\n    in = null;\n  }\n\n  static Counters fromAvro(JhCounters counters) {","sourceCodeStart":152,"sourceCodeEnd":188,"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/EventReader.java#L152-L188","documentation":"EventReader.getNextEvent maps each decoded Avro Event wrapper's EventType (JOB_SUBMITTED, TASK_FINISHED, AM_STARTED, ...) to a concrete HistoryEvent class via a switch. The default branch throws RuntimeException(\"unexpected event type\") for a type with no mapping - reachable only when the history contains an EventType this build does not know (newer writer) or the decoded payload is garbage.","triggerScenarios":"Reading a .jhist written by a newer Hadoop build or fork that added EventType constants unknown to this reader; Avro decoding producing a corrupt type value from a damaged stream.","commonSituations":"Parsing history across Hadoop versions (downgrade direction); patched Hadoop with extra event types; history files damaged in storage.","solutions":["Read the history with a Hadoop version equal to or newer than the one that wrote it.","Skip the unreadable file and continue the scan (one bad file should not abort directory-level tooling).","If you fork and add event types, add the mapping case in EventReader in the same change.","Treat persistent occurrences as corruption: recover via HDFS replicas or re-run."],"exampleFix":"// defensive directory scan pattern\ntry {\n  HistoryEvent e = reader.getNextEvent();\n} catch (RuntimeException re) {\n  if (re.getMessage() != null && re.getMessage().startsWith(\"unexpected event type\")) {\n    LOG.warn(\"History from newer Hadoop? Skipping \" + path);\n    continue; // skip file, keep scanning\n  }\n  throw re;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) from getNextEvent(): if message starts with \"unexpected event type\", skip the remainder of that file (likely newer-format history) and continue the scan; otherwise propagate.","preventionTips":["Read history with a Hadoop version >= the writer's version.","In forks adding event types, update EventReader's switch in the same commit.","Isolate per-file parsing so one bad file cannot abort a batch."],"tags":["hadoop","mapreduce","jobhistory","enum","runtimeexception","version-skew"],"backgroundTag":"unhandled-enum-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}