{"record":{"id":"9ea252d122203354","repo":"apache/hadoop","slug":"replica-of-type-getstate-does-not-support-set-9ea252","errorCode":null,"errorMessage":"Replica of type ${getState()} does not support setRecoveryID","messagePattern":"Replica of type (.+?) does not support setRecoveryID","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FinalizedReplica.java","lineNumber":138,"sourceCode":"  public String toString() {\n    return super.toString();\n  }\n\n  @Override\n  public ReplicaInfo getOriginalReplica() {\n    throw new UnsupportedOperationException(\"Replica of type \" + getState() +\n        \" does not support getOriginalReplica\");\n  }\n\n  @Override\n  public long getRecoveryID() {\n    throw new UnsupportedOperationException(\"Replica of type \" + getState() +\n        \" does not support getRecoveryID\");\n  }\n\n  @Override\n  public void setRecoveryID(long recoveryId) {\n    throw new UnsupportedOperationException(\"Replica of type \" + getState() +\n        \" does not support setRecoveryID\");\n  }\n\n  @Override\n  public ReplicaRecoveryInfo createInfo() {\n    throw new UnsupportedOperationException(\"Replica of type \" + getState() +\n        \" does not support createInfo\");\n  }\n\n  @Override\n  public long getMetadataLength() {\n    if (metaLength < 0) {\n      metaLength = (int)super.getMetadataLength();\n    }\n    return metaLength;\n  }\n\n  public byte[] getLastPartialChunkChecksum() {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FinalizedReplica.java#L120-L156","documentation":"setRecoveryID() stores the ID assigned at the start of a recovery session; a FINALIZED FinalizedReplica is not part of any recovery session and refuses the mutation with UnsupportedOperationException. This is a state-machine violation by the caller, not a runtime condition to retry.","triggerScenarios":"Recovery code calling setRecoveryID(id) on a replica whose state is FINALIZED — typically a missing state filter before mutating recovery bookkeeping.","commonSituations":"Custom truncate/append handling; patched recovery flows; tooling that resets recovery IDs on all replicas.","solutions":["Guard the call with a state check and only set recovery IDs on RUR/RBW/RWR replicas.","Review the surrounding recovery flow: a finalized replica being pulled into recovery usually signals the wrong replica was selected.","Add unit coverage for the finalized-replica case.","Upgrade if the unguarded call site is in released framework code."],"exampleFix":"// before\nreplica.setRecoveryID(newId);\n\n// after\nif (replica instanceof ReplicaUnderReconstruction) {\n  replica.setRecoveryID(newId);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean canSetRecoveryId(ReplicaInfo r) {\n  return r instanceof ReplicaUnderReconstruction;\n}","tryCatchPattern":"try {\n  replica.setRecoveryID(newId);\n} catch (UnsupportedOperationException e) {\n  // FINALIZED replica pulled into recovery: wrong replica selected — fix caller logic\n}","preventionTips":["Mutate recovery IDs only on RUR/RBW/RWR replicas","Investigate why a finalized replica entered a recovery session; usually the participant selection is wrong","Keep tests covering both finalized and under-reconstruction replicas in recovery paths"],"tags":["replica","finalized","recovery","unsupported-operation","hdfs","datanode"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}