{"record":{"id":"9ae1b39754ce50e2","repo":"apache/hadoop","slug":"instance-is-not-set","errorCode":null,"errorMessage":"instance is not set","messagePattern":"instance is not set","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java","lineNumber":986,"sourceCode":"    public Builder setAlignmentContext(AlignmentContext alignmentContext) {\n      this.alignmentContext = alignmentContext;\n      return this;\n    }\n\n    /**\n     * @return Build the RPC Server.\n     * @throws IOException on error\n     * @throws HadoopIllegalArgumentException when mandatory fields are not set\n     */\n    public Server build() throws IOException, HadoopIllegalArgumentException {\n      if (this.conf == null) {\n        throw new HadoopIllegalArgumentException(\"conf is not set\");\n      }\n      if (this.protocol == null) {\n        throw new HadoopIllegalArgumentException(\"protocol is not set\");\n      }\n      if (this.instance == null) {\n        throw new HadoopIllegalArgumentException(\"instance is not set\");\n      }\n      \n      return getProtocolEngine(this.protocol, this.conf).getServer(\n          this.protocol, this.instance, this.bindAddress, this.port,\n          this.numHandlers, this.numReaders, this.queueSizePerHandler,\n          this.verbose, this.conf, this.secretManager, this.portRangeConfig,\n          this.alignmentContext);\n    }\n  }\n  \n  /** An RPC Server. */\n  public abstract static class Server extends org.apache.hadoop.ipc.Server {\n\n    boolean verbose;\n\n    private static final Pattern COMPLEX_SERVER_NAME_PATTERN =\n        Pattern.compile(\"(?:[^\\\\$]*\\\\$)*([A-Za-z][^\\\\$]+)(?:\\\\$\\\\d+)?\");\n","sourceCodeStart":968,"sourceCodeEnd":1004,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java#L968-L1004","documentation":"RPC.Server.Builder.build() requires the protocol implementation instance (the object that will receive calls) and throws HadoopIllegalArgumentException(\"instance is not set\") when .setInstance was never called. A protocol interface without a serving instance cannot be exported.","triggerScenarios":"Calling build() without .setInstance(impl); wiring code that intended to pass the implementation but passed null because construction of the implementation failed earlier.","commonSituations":"Builders assembled by DI frameworks where the instance bean was missing; test servers configured with only conf and protocol; refactors that moved instance creation after build().","solutions":["Call .setInstance(implementation) with the non-null object implementing the protocol before build().","Check the instance reference right after construction and fail with a descriptive error if it is null.","Construct the implementation before the builder chain starts so the reference is provably non-null."],"exampleFix":"// before\nServer s = new RPC.Server.Builder()\n    .setConf(conf)\n    .setProtocol(MyProtocol.class)\n    .build(); // throws: instance is not set\n// after\nMyProtocol impl = new MyProtocolImpl();\nServer s = new RPC.Server.Builder()\n    .setConf(conf)\n    .setProtocol(MyProtocol.class)\n    .setInstance(impl)\n    .build();","handlingStrategy":"validation","validationCode":"MyProtocol impl = constructImplementation();\nObjects.requireNonNull(impl, \"protocol implementation required\");\nnew RPC.Server.Builder().setConf(conf).setProtocol(MyProtocol.class)\n    .setInstance(impl).build();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct the protocol implementation before starting the builder chain.","Validate DI-provided beans for null before wiring them into the server builder."],"tags":["rpc","server","builder","dependency-injection"],"backgroundTag":"missing-required-field","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}