{"record":{"id":"905cd022400cfd84","repo":"apache/hadoop","slug":"null-param-while-calling-method","errorCode":null,"errorMessage":"null param while calling Method: [{}]","messagePattern":"null param while calling Method: \\[(.+?)\\]","errorType":"validation","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java","lineNumber":227,"sourceCode":"     * cause is RemoteException, then unwrap it to get the exception thrown by\n     * the server.\n     */\n    @Override\n    public Message invoke(Object proxy, final Method method, Object[] args)\n        throws ServiceException {\n      long startTime = 0;\n      if (LOG.isDebugEnabled()) {\n        startTime = Time.monotonicNow();\n      }\n      \n      if (args.length != 2) { // RpcController + Message\n        throw new ServiceException(\n            \"Too many or few parameters for request. Method: [\"\n            + method.getName() + \"]\" + \", Expected: 2, Actual: \"\n            + args.length);\n      }\n      if (args[1] == null) {\n        throw new ServiceException(\"null param while calling Method: [\"\n            + method.getName() + \"]\");\n      }\n\n      // if Tracing is on then start a new span for this rpc.\n      // guard it in the if statement to make sure there isn't\n      // any extra string manipulation.\n      Tracer tracer = Tracer.curThreadTracer();\n      TraceScope traceScope = null;\n      if (tracer != null) {\n        traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method));\n      }\n\n      if (LOG.isTraceEnabled()) {\n        LOG.trace(Thread.currentThread().getId() + \": Call -> \" +\n            remoteId + \": \" + method.getName() +\n            \" {\" + TextFormat.shortDebugString((Message) args[1]) + \"}\");\n      }\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java#L209-L245","documentation":"The same ProtobufRpcEngine InvocationHandler rejects args[1] == null: a protobuf RPC always carries exactly one request Message, and null cannot be serialized to the wire format, so ServiceException('null param while calling Method: [m]') is thrown client-side before connecting. It is a pure caller bug — the request object was never built or was lost.","triggerScenarios":"Passing null explicitly as the request message (proxy.method(null, null)); a builder chain that returns null on error and is forwarded unchecked; helper wrappers that accept null and blindly forward when the caller omits the request.","commonSituations":"Quick test code calling translators with null; Optional/defaulting logic that maps 'no request' to null instead of a default instance (Message.getDefaultInstance()); refactors that swapped argument order.","solutions":["Always pass a real request Message; for empty requests use MyRequestProto.getDefaultInstance().","Null-check args at the wrapper/translator boundary and fail with a clearer message.","Enable the protocol's builder validation so malformed requests surface earlier."],"exampleFix":"// before\nGetFileInfoResponseProto resp = proxy.getFileInfo(null, null); // null request\n\n// after\nGetFileInfoResponseProto resp = proxy.getFileInfo(null,\n    GetFileInfoRequestProto.newBuilder().setPath(\"/\").build());","handlingStrategy":"validation","validationCode":"// before invoking through the PB proxy\njava.util.Objects.requireNonNull(requestProto,\n    \"request message for \" + methodName + \" must not be null\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use MyRequestProto.getDefaultInstance() for empty requests instead of null.","Make builder helpers never return null (return the default instance or throw).","requireNonNull at wrapper boundaries for clearer diagnostics than the engine's generic message."],"tags":["hadoop","ipc","rpc","protobuf","null-argument","validation"],"backgroundTag":"null-argument-rejected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}