OpenFeign/feign · error · UnsupportedOperationException

Method \" \" should not be called

Error message

Method \"%s\" should not be called

What it means

ReactiveInvocationHandler handles the proxy's Object methods (equals, hashCode, toString) and a fixed dispatch table of interface methods. If the proxy is invoked with a Method that is neither an Object method nor present in the dispatch table, it throws UnsupportedOperationException naming the method, indicating the proxy was reached through an unexpected method surface.

Solutions

  1. Only call methods declared on the target Feign interface through the proxy; avoid calling interface default methods directly on the proxy
  2. If wrapping the proxy, unwrap to the raw proxy before reflective invocation, or register the method in the InvocationHandlerFactory dispatch table
  3. Use a custom ReactiveInvocationHandler whose dispatch includes default-method handling

Example fix

// before
proxy.getClass().getMethod("someDefaultMethod").invoke(proxy); // not in dispatch
// after
// call only abstract @RequestLine methods, or implement the default logic outside the proxy
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Arrays.asList(Api.class.getMethods()).contains(method)
    && !"equals".equals(method.getName())
    && !"hashCode".equals(method.getName())
    && !"toString".equals(method.getName()))
  throw new IllegalStateException("Method not part of the Feign interface: " + method);

Type guard

static boolean isCallableOnProxy(java.lang.reflect.Method m, Class<?> api) {
  return Arrays.asList(api.getMethods()).contains(m);
}

Try / catch

try {
  return proxy.someApiMethod(args);
} catch (UnsupportedOperationException e) {
  // a method outside the interface dispatch was invoked; fix the caller, not retry
}

Prevention

When it happens

Trigger: Invoking a default interface method, synthetic bridge, or a method obtained from a different class/interface on the reactive proxy; reflective calls through a Method object that does not match the target interface's declared methods.

Common situations: AOP/proxying frameworks (Spring AOP, mocking libs) wrapping the Feign proxy and calling synthetic methods; calling default methods of the interface; Java version differences introducing bridges the dispatch map does not contain.


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/3ab9c79c28cebf22. Report an issue: GitHub.

Appendix: source

Thrown at reactive/src/main/java/feign/reactive/ReactiveInvocationHandler.java:53

    this.dispatch = dispatch;
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if ("equals".equals(method.getName())) {
      try {
        Object otherHandler =
            args.length > 0 && args[0] != null ? Proxy.getInvocationHandler(args[0]) : null;
        return equals(otherHandler);
      } catch (IllegalArgumentException e) {
        return false;
      }
    } else if ("hashCode".equals(method.getName())) {
      return hashCode();
    } else if ("toString".equals(method.getName())) {
      return toString();
    } else if (!dispatch.containsKey(method)) {
      throw new UnsupportedOperationException(
          String.format("Method \"%s\" should not be called", method.getName()));
    }
    return this.invoke(method, this.dispatch.get(method), args);
  }

  @Override
  public int hashCode() {
    return this.target.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (obj == this) {
      return true;
    }

View on GitHub (pinned to e2a1e27560)