{"record":{"id":"590cfcc557b360e6","repo":"apache/hadoop","slug":"replica-of-type-does-not-support-getoriginalrep","errorCode":null,"errorMessage":"Replica of type {} 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/ReplicaWaitingToBeRecovered.java","lineNumber":101,"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 getRecoveryID\");\n  }\n\n  @Override\n  public ReplicaRecoveryInfo createInfo() {\n    throw new UnsupportedOperationException(\"Replica of type \" + getState() +","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ReplicaWaitingToBeRecovered.java#L83-L119","documentation":"ReplicaWaitingToBeRecovered (state RWR) deliberately does not support the recovery-info API surface: getOriginalReplica() throws UnsupportedOperationException because an RWR replica is not a wrapper around some other replica. Recovery metadata only exists on ReplicaUnderRecovery. This is a programming error, not an environmental condition.","triggerScenarios":"Calling getOriginalReplica() on any ReplicaInfo whose runtime type is ReplicaWaitingToBeRecovered - e.g., generic recovery code that assumes every non-finalized replica is under recovery and calls getOriginalReplica() without an instanceof check.","commonSituations":"Custom FsDataset implementations or tests that iterate the volume map during recovery and call the recovery API uniformly on all replicas; misclassifying RWR (replica waiting to be recovered because its datanode was down) as RUR (replica under recovery).","solutions":["Guard with instanceof ReplicaUnderRecovery before calling getOriginalReplica()","Or gate on state: only ReplicaState.RUR exposes recovery info; skip FINALIZED/RBW/RWR/TEMPORARY","Re-check your recovery flow: RWR replicas become recoverable via ReplicaUnderRecovery wrapping, not directly"],"exampleFix":"// before\nReplicaInfo original = r.getOriginalReplica(); // throws for RWR\n\n// after\nReplicaInfo original = (r instanceof ReplicaUnderRecovery)\n    ? ((ReplicaUnderRecovery) r).getOriginalReplica()\n    : r;","handlingStrategy":"type-guard","validationCode":"if (!(r instanceof ReplicaUnderRecovery)) { /* RWR and others: use r itself */ }","typeGuard":"static boolean hasOriginalReplica(ReplicaInfo r) {\n  return r instanceof ReplicaUnderRecovery;\n}\n// ReplicaInfo original = hasOriginalReplica(r) ? ((ReplicaUnderRecovery) r).getOriginalReplica() : r;","tryCatchPattern":"try { r.getOriginalReplica(); } catch (UnsupportedOperationException e) { /* not under recovery: fall back to treating r as the original */ }","preventionTips":["Never call recovery-info APIs without an instanceof ReplicaUnderRecovery check","Remember the state model: RUR wraps an original; RWR/RBW/FINALIZED/TEMPORARY do not"],"tags":["hdfs","datanode","block-recovery","replica","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}