{"record":{"id":"97868a7a4efd0ebe","repo":"apache/hadoop","slug":"replica-of-type-getstate-does-not-support-get-97868a","errorCode":null,"errorMessage":"Replica of type ${getState()} does not support getOriginalReplica","messagePattern":"Replica of type (.+?) does not support getOriginalReplica","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":126,"sourceCode":"\n  @Override  // Object\n  public boolean equals(Object o) {\n    return super.equals(o);\n  }\n  \n  @Override  // Object\n  public int hashCode() {\n    return super.hashCode();\n  }\n  \n  @Override\n  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() +","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FinalizedReplica.java#L108-L144","documentation":"FinalizedReplica is a FINALIZED local replica. getOriginalReplica() returns the pre-truncation view of a replica and is implemented only by ReplicaUnderReconstruction; a finalized replica has no 'original' twin. Hitting this UnsupportedOperationException means the caller invoked a recovery API on a replica in the wrong state — a caller-side logic bug, not an environmental failure.","triggerScenarios":"Internal DataNode or custom code calling getOriginalReplica() on a replica whose getState() is FINALIZED — e.g., truncate/recovery logic that skipped its state check, or code that assumes every ReplicaInfo implements the full recovery API.","commonSituations":"Custom FsDataset implementations and tests that iterate the volume map and call recovery APIs uniformly; modified truncate-handling code that loses a state check; version upgrades adding new call sites that were never exercised against finalized replicas.","solutions":["Fix the caller: only call getOriginalReplica() when the replica is under reconstruction (instanceof ReplicaUnderReconstruction).","Add a state assertion (ReplicaState.RUR/RBW/RWR) before recovery-API call sites.","Write a unit test that drives the same flow against a FINALIZED replica to lock in the guard.","If the call comes from framework code in a released Hadoop version, check for a fixed version and upgrade."],"exampleFix":"// before\nReplicaInfo original = replica.getOriginalReplica();\n\n// after: guard by replica type\nif (replica instanceof ReplicaUnderReconstruction) {\n  ReplicaInfo original = replica.getOriginalReplica();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean supportsGetOriginalReplica(ReplicaInfo r) {\n  return r instanceof ReplicaUnderReconstruction;\n}","tryCatchPattern":"try {\n  ReplicaInfo original = replica.getOriginalReplica();\n} catch (UnsupportedOperationException e) {\n  // FINALIZED replica in a truncate/recovery path: caller bug — fix the state check\n}","preventionTips":["Only call getOriginalReplica() on ReplicaUnderReconstruction instances","Add state assertions before recovery-API call sites in custom dataset code","Unit-test recovery flows with FINALIZED replicas present in the volume map"],"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-22T20:17:22.307Z"}