{"record":{"id":"70dd906ede592916","repo":"apache/hadoop","slug":"unexpected-haservicestate","errorCode":null,"errorMessage":"Unexpected HAServiceState:","messagePattern":"Unexpected HAServiceState:","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java","lineNumber":805,"sourceCode":"    default:\n      throw new IllegalArgumentException(\"Unexpected HAServiceStateProto:\"\n          + s);\n    }\n  }\n\n  public static NNHAStatusHeartbeatProto.State convert(HAServiceState s) {\n    if (s == null) {\n      return null;\n    }\n    switch (s) {\n    case ACTIVE:\n      return NNHAStatusHeartbeatProto.State.ACTIVE;\n    case STANDBY:\n      return NNHAStatusHeartbeatProto.State.STANDBY;\n    case OBSERVER:\n      return NNHAStatusHeartbeatProto.State.OBSERVER;\n    default:\n      throw new IllegalArgumentException(\"Unexpected HAServiceState:\"\n          + s);\n    }\n  }\n\n  public static NNHAStatusHeartbeat convert(NNHAStatusHeartbeatProto s) {\n    if (s == null) {\n      return null;\n    }\n    return new NNHAStatusHeartbeat(convert(s.getState()), s.getTxid());\n  }\n\n  public static NNHAStatusHeartbeatProto convert(NNHAStatusHeartbeat hb) {\n    if (hb == null) {\n      return null;\n    }\n    NNHAStatusHeartbeatProto.Builder builder =\n        NNHAStatusHeartbeatProto.newBuilder();\n    builder.setState(convert(hb.getState()));","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java#L787-L823","documentation":"Inverse of the heartbeat-state converter: maps HAServiceState onto the NNHAStatusHeartbeatProto.State wire enum. Only ACTIVE, STANDBY and OBSERVER are mappable; any other HAServiceState constant (added by a newer or custom build) cannot be serialized and throws IllegalArgumentException.","triggerScenarios":"Calling PBHelper.convert(HAServiceState) with a constant this build's PBHelper does not know — e.g. newer caller code linked against an older hadoop-hdfs jar, or a custom HAServiceState extension.","commonSituations":"Duplicate/mismatched hadoop-hdfs jars on the classpath (shaded or vendored copies); partial upgrades where new NN code invokes old serialization helpers; custom HA extensions.","solutions":["Verify a single consistent Hadoop version on the classpath (inspect for duplicate hadoop-hdfs / hadoop-common jars).","Pass only ACTIVE/STANDBY/OBSERVER to the converter.","Upgrade the module containing PBHelper to the release that defines the new state constant."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import org.apache.hadoop.ha.HAServiceState;\nimport java.util.EnumSet;\n\nstatic final EnumSet<HAServiceState> SERIALIZABLE =\n    EnumSet.of(HAServiceState.ACTIVE, HAServiceState.STANDBY,\n               HAServiceState.OBSERVER);\n\nif (!SERIALIZABLE.contains(state)) {\n  throw new IllegalStateException(\n      \"HAServiceState \" + state + \" not supported by this hadoop-hdfs build; \"\n    + \"check for mixed jar versions\");\n}","typeGuard":"static boolean isSerializableHAState(HAServiceState s) {\n  return s == HAServiceState.ACTIVE\n      || s == HAServiceState.STANDBY\n      || s == HAServiceState.OBSERVER;\n}","tryCatchPattern":"try {\n  protoBuilder.setState(PBHelper.convert(state));\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"HAServiceState:\")) {\n    throw new IllegalStateException(\n        \"Mixed Hadoop versions on classpath; cannot serialize state \" + state, e);\n  }\n  throw e;\n}","preventionTips":["Keep exactly one version of hadoop-hdfs and hadoop-common on the classpath; detect duplicates in CI.","When adding a new HAServiceState in forks, update both convert directions in the same change.","Fail fast at startup by round-tripping every enum you will serialize."],"tags":["hadoop","hdfs","ha","protobuf","enum","classpath"],"backgroundTag":"enum-deserialization-unknown-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}