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

Đang mở Phù hợp với người mới
#1,813 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, spring
Lĩnh vực
api, backend

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ả

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.

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-commons

Tất cả issue của spring-cloud/spring-cloud-commons

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.