{"record":{"id":"71c45f25752ea0cc","repo":"apache/hadoop","slug":"a-valid-writer-is-required-for-constructing-a-rbw","errorCode":null,"errorMessage":"A valid writer is required for constructing a RBW from block {}","messagePattern":"A valid writer is required for constructing a RBW from block (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ReplicaBuilder.java","lineNumber":212,"sourceCode":"    case TEMPORARY:\n      info = buildTemporaryReplica();\n      break;\n    default:\n      throw new IllegalArgumentException(\"Unknown replica state \" + state);\n    }\n    return info;\n  }\n\n  private LocalReplicaInPipeline buildRBW() throws IllegalArgumentException {\n    if (null != fromReplica && fromReplica.getState() == ReplicaState.RBW) {\n      return new ReplicaBeingWritten((ReplicaBeingWritten) fromReplica);\n    } else if (null != fromReplica) {\n      throw new IllegalArgumentException(\"Incompatible fromReplica \"\n          + \"state: \" + fromReplica.getState());\n    } else {\n      if (null != block) {\n        if (null == writer) {\n          throw new IllegalArgumentException(\"A valid writer is \"\n              + \"required for constructing a RBW from block \"\n              + block.getBlockId());\n        }\n        return new ReplicaBeingWritten(block, volume, directoryUsed, writer);\n      } else {\n        if (length != -1) {\n          return new ReplicaBeingWritten(blockId, length, genStamp,\n              volume, directoryUsed, writer, bytesToReserve);\n        } else {\n          return new ReplicaBeingWritten(blockId, genStamp, volume,\n              directoryUsed, bytesToReserve);\n        }\n      }\n    }\n  }\n\n  private LocalReplicaInPipeline buildTemporaryReplica()\n      throws IllegalArgumentException {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ReplicaBuilder.java#L194-L230","documentation":"When ReplicaBuilder constructs a ReplicaBeingWritten from a Block (setBlock) rather than from an existing replica, it requires a live writer thread (setWriterThread) - the RBW replica tracks the thread writing its bytes for interruption/monitoring. If writer is null it throws IllegalArgumentException 'A valid writer is required for constructing a RBW from block'.","triggerScenarios":"new ReplicaBuilder(ReplicaState.RBW).setBlock(block).buildLocalReplicaInPipeline() without a prior .setWriterThread(...) call - the block branch of buildRBW() finds a null writer and throws.","commonSituations":"Test code or refactored DataNode write paths that build RBW replicas from a Block object but forget the writer thread; copied code from finalized-replica construction where no writer is needed.","solutions":["Add .setWriterThread(Thread.currentThread()) (or the actual writer thread) before build when using setBlock.","Alternatively build from raw fields (setBlockId/setGenerationStamp/setFsVolume/setDirectoryToUse/setWriterThread/setBytesToReserved) instead of setBlock - the writer is still required for in-pipeline replicas.","Fail fast in your wrapper: assert writer is set before invoking the builder."],"exampleFix":"// before\nLocalReplicaInPipeline r = new ReplicaBuilder(ReplicaState.RBW)\n    .setBlock(block).buildLocalReplicaInPipeline();\n\n// after\nLocalReplicaInPipeline r = new ReplicaBuilder(ReplicaState.RBW)\n    .setBlock(block)\n    .setWriterThread(Thread.currentThread())\n    .buildLocalReplicaInPipeline();","handlingStrategy":"validation","validationCode":"if (block != null && writer == null) {\n  throw new IllegalStateException(\n      \"setWriterThread is required when building an RBW from a Block\");\n}\nLocalReplicaInPipeline r = new ReplicaBuilder(ReplicaState.RBW)\n    .setBlock(block)\n    .setWriterThread(Thread.currentThread())\n    .buildLocalReplicaInPipeline();","typeGuard":null,"tryCatchPattern":"try {\n  r = builder.buildLocalReplicaInPipeline();\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"RBW construction failed (missing writer): \"\n      + e.getMessage(), e);\n}","preventionTips":["Treat setWriterThread as mandatory whenever setBlock is used for in-pipeline replicas.","Wrap builder usage in a factory method that enforces the writer/block pairing.","Write a unit test constructing RBW from a Block to catch missing-writer regressions."],"tags":["hdfs","datanode","replica","builder","rbw","required-parameter"],"backgroundTag":"missing-builder-parameter","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}