apache/hadoop · error · ServiceException

Too many or few parameters for request. Method: [{}], Expect

Error message

Too many or few parameters for request. Method: [{}], Expected: 2, Actual: {}

What it means

ProtobufRpcEngine2 (the protobuf-v2/default engine in newer Hadoop) has the identical client-side InvocationHandler contract: every method invoked through the proxy must take exactly (RpcController, Message). args.length != 2 throws ServiceException before any network activity. It indicates a non-RPC method was routed through the engine-2 proxy.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine2.java:230

     * <li>Exceptions from the server are wrapped in RemoteException and are
     * set as cause in ServiceException</li>
     * </ol>
     *
     * Note that the client calling protobuf RPC methods, must handle
     * ServiceException by getting the cause from the ServiceException. If the
     * cause is RemoteException, then unwrap it to get the exception thrown by
     * the server.
     */
    @Override
    public Message invoke(Object proxy, final Method method, Object[] args)
        throws ServiceException {
      long startTime = 0;
      if (LOG.isDebugEnabled()) {
        startTime = Time.monotonicNow();
      }

      if (args.length != 2) { // RpcController + Message
        throw new ServiceException(
            "Too many or few parameters for request. Method: ["
            + method.getName() + "]" + ", Expected: 2, Actual: "
            + args.length);
      }
      if (args[1] == null) {
        throw new ServiceException("null param while calling Method: ["
            + method.getName() + "]");
      }

      // if Tracing is on then start a new span for this rpc.
      // guard it in the if statement to make sure there isn't
      // any extra string manipulation.
      Tracer tracer = Tracer.curThreadTracer();
      TraceScope traceScope = null;
      if (tracer != null) {
        traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method));
      }

View on GitHub (pinned to 2add963021)

Solutions

  1. Restrict the PB protocol interface to 2-arg (RpcController, Message) methods; move helpers to translators or separate interfaces.
  2. Call default/interface helper methods on a typed reference, not through the RPC proxy.
  3. Guard reflective invocations with a signature check (parameter count == 2).

Example fix

// before
public interface StoreProtocolPB {
  StoreResponseProto put(RpcController c, StoreRequestProto req);
  void close(); // 0-arg helper -> ServiceException when invoked via proxy
}
proxy.close();

// after
public interface StoreProtocolPB {
  StoreResponseProto put(RpcController c, StoreRequestProto req);
}
// close() moved to the translator class that owns the proxy lifecycle
Defensive patterns

Strategy: validation

Validate before calling

for (Method m : protoInterface.getMethods()) {
  if (m.getParameterCount() != 2) {
    throw new IllegalStateException("ProtobufRpcEngine2 requires exactly 2-arg methods, found: " + m);
  }
}

Type guard

static boolean isProtobufRpcMethod(Method m) {
  Class<?>[] p = m.getParameterTypes();
  return p.length == 2
      && RpcController.class.isAssignableFrom(p[0])
      && com.google.protobuf.Message.class.isAssignableFrom(p[1]);
}

Prevention

When it happens

Trigger: Adding convenience/default methods with other arities to a protocolPB interface and calling them on the proxy; reflective invocation that reshapes the argument array; using the PB proxy where the translator should be used.

Common situations: Custom protocols migrating to ProtobufRpcEngine2 (proto3); library upgrades where interfaces gained default helper methods; generic proxy wrappers (caching, metrics) that call toString/equals-like extras reflectively.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/77b638dc466a2169. Report an issue: GitHub.