{"record":{"id":"f8a8db9880f8db2a","repo":"apache/hadoop","slug":"protocol-is-not-set","errorCode":null,"errorMessage":"protocol is not set","messagePattern":"protocol 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":983,"sourceCode":"     * @return Default: null.\n     * @param alignmentContext input alignmentContext.\n     */\n    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","sourceCodeStart":965,"sourceCodeEnd":1001,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java#L965-L1001","documentation":"RPC.Server.Builder.build() requires the protocol interface (the RPC contract class) and throws HadoopIllegalArgumentException(\"protocol is not set\") when .setProtocol was never called. The protocol class determines which RPC engine and method dispatcher the server uses.","triggerScenarios":"Calling build() without .setProtocol(...); passing a protocol class resolved by name (e.g., Class.forName) where the lookup failed and produced null.","commonSituations":"Config-driven server construction where the protocol class name is mistyped or the class is not on the classpath; trimmed builder chains in tests and examples.","solutions":["Call .setProtocol(YourProtocol.class) before build().","When resolving the protocol class by name, fail with a clear error when the class cannot be loaded instead of passing null.","Keep the builder chain for a server in one place so all mandatory setters stay together."],"exampleFix":"// before\nServer s = new RPC.Server.Builder()\n    .setConf(conf)\n    .setInstance(impl)\n    .build(); // throws: protocol is not set\n// after\nServer s = new RPC.Server.Builder()\n    .setConf(conf)\n    .setProtocol(MyProtocol.class)\n    .setInstance(impl)\n    .build();","handlingStrategy":"validation","validationCode":"Class<?> proto = resolveProtocolClass(); // e.g. Class.forName with error handling\nif (proto == null) {\n  throw new IllegalStateException(\"protocol class could not be resolved\");\n}\nnew RPC.Server.Builder().setConf(conf).setProtocol(proto)...build();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all mandatory setters (conf, protocol, instance) in one builder chain in one place.","Fail with a clear message when config-driven class resolution returns nothing instead of passing null onward."],"tags":["rpc","server","builder","protocol"],"backgroundTag":"missing-required-field","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}