HttpServiceProxyFactory proxy throws IllegalStateException when toString() is invoked on HTTP service interface proxy
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先阅读 HttpServiceProxyFactory.HttpServiceMethodInterceptor,尤其是它的 invoke 方法以及 issue 中提到的 Object 方法情况。检查附近有关 HTTP 服务代理行为的测试,并为 toString()、equals() 和 hashCode() 添加测试覆盖。当这些调用不再抛出异常且现有代理测试通过时,issue 就完成了。
由索引模型根据 Issue 内容生成。
描述
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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
spring-cloud/spring-cloud-commons 的其他 Issue
-
enhancement for team discussion
难度 5/5 一周以上 新手友好度 42/100
spring-cloud/spring-cloud-commons#1676 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 5/5 一周以上 新手友好度 38/100
spring-cloud/spring-cloud-commons#1675 · 1 条评论 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 4/5 3-5 天 新手友好度 42/100
spring-cloud/spring-cloud-commons#1640 · 1 条评论 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 4/5 3-5 天 新手友好度 35/100
spring-cloud/spring-cloud-commons#1629 · 2 条评论 ·
维护者通常 1 天内回复
-
enhancement help wanted
难度 4/5 3-5 天 新手友好度 35/100
spring-cloud/spring-cloud-commons#1619 · 6 条评论 ·
维护者通常 1 天内回复
查看 spring-cloud/spring-cloud-commons 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
NucleusFramework/Nucleus#1020 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 83/100
ajeetraina/awesome-docker-sbx#839 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
portfolio-performance/portfolio#6459 ·
维护者通常 2 天内回复
-
Bug
难度 2/5 1-3 小时 新手友好度 75/100
bufbuild/protovalidate-java#564 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 83/100
it-at-m/traegerportal#17 ·