HttpServiceProxyFactory proxy throws IllegalStateException when toString() is invoked on HTTP service interface proxy
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc HttpServiceProxyFactory.HttpServiceMethodInterceptor, đặc biệt là phương thức invoke và các trường hợp phương thức Object được nêu trong issue. Kiểm tra các bài kiểm thử gần đó về hành vi của proxy dịch vụ HTTP và bổ sung kiểm thử cho toString(), equals() và hashCode(). Issue được xem là hoàn tất khi các lời gọi này không còn ném ngoại lệ và các bài kiểm thử proxy hiện có đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 751
- Fork
- 771
- Merge trung bình
- 3 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 19
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của spring-cloud/spring-cloud-commons
-
enhancement for team discussion
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
spring-cloud/spring-cloud-commons#1676 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
waiting-for-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
spring-cloud/spring-cloud-commons#1675 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
waiting-for-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
spring-cloud/spring-cloud-commons#1640 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
waiting-for-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
spring-cloud/spring-cloud-commons#1629 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
spring-cloud/spring-cloud-commons#1619 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của spring-cloud/spring-cloud-commons
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NucleusFramework/Nucleus#1020 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
ajeetraina/awesome-docker-sbx#839 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
portfolio-performance/portfolio#6459 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
bufbuild/protovalidate-java#564 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
it-at-m/traegerportal#17 ·