HttpServiceProxyFactory proxy throws IllegalStateException when toString() is invoked on HTTP service interface proxy

未关闭 适合新手
#1,813 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, spring
领域
api, backend

调研方向

先阅读 HttpServiceProxyFactory.HttpServiceMethodInterceptor,尤其是它的 invoke 方法以及 issue 中提到的 Object 方法情况。检查附近有关 HTTP 服务代理行为的测试,并为 toString()、equals() 和 hashCode() 添加测试覆盖。当这些调用不再抛出异常且现有代理测试通过时,issue 就完成了。

由索引模型根据 Issue 内容生成。

描述

waiting-for-triage

When using an HTTP service interface created through HttpServiceProxyFactory, invoking Object.toString() on the generated proxy causes an IllegalStateException.
The issue becomes visible during Spring Cloud bootstrap logging because a PropertySource contains a ConsulClient proxy and PropertySource.toString() indirectly invokes toString() on that proxy.
Expected behavior:
• HTTP service proxies should safely handle toString(), equals() and hashCode()
• Logging a structure containing such proxies should not fail
Actual behavior:
• Object.toString() invocation reaches HttpServiceMethodInterceptor
• HttpServiceMethodInterceptor throws:

IllegalStateException:
Unexpected method invocation:
public java.lang.String java.lang.Object.toString()

Stack Trace

java.lang.IllegalStateException:
Unexpected method invocation:
public java.lang.String java.lang.Object.toString()
 
at org.springframework.web.service.invoker.HttpServiceProxyFactory$HttpServiceMethodInterceptor.invoke(HttpServiceProxyFactory.java:308)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:222)
at jdk.proxy2.$Proxy54.toString(Unknown Source)

Relevant Code
Current implementation:

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
 
Method method = invocation.getMethod();
 
HttpServiceMethod httpServiceMethod =
this.httpServiceMethods.get(method);
 
if (httpServiceMethod != null) {
return httpServiceMethod.invoke(arguments);
}
 
if (method.isDefault()) {
...
}
 
throw new IllegalStateException(
"Unexpected method invocation: " + method);
}

The interceptor does not handle:

Object.toString()
Object.equals()
Object.hashCode()

and therefore fails when any of those methods are invoked.


Minimal Reproducer
HTTP service interface:

public interface DemoClient {
 
@GetExchange("/demo")
String demo();
}

Proxy creation:

DemoClient client =
HttpServiceProxyFactory.builderFor(adapter)
.build()
.createClient(DemoClient.class);

Trigger:
System.out.println(client.toString());
Result:

IllegalStateException:
Unexpected method invocation:
public java.lang.String java.lang.Object.toString()

Expected Behavior
The generated proxy should support standard Object methods, for example:

client.toString();
client.hashCode();
client.equals(other);

without throwing exceptions.


Additional Context
The issue became visible after migrating from a traditional Consul client implementation to the new Spring HTTP Interface based ConsulClient.
The problem is not related to Consul itself, but to the generic handling of Object methods by HttpServiceProxyFactory generated proxies.

主要语言
Java
星标
751
派生
771
平均合并
3 天 15 小时
30 天内合并 PR
19

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-cloud/spring-cloud-commons 的其他 Issue

查看 spring-cloud/spring-cloud-commons 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。