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

オープン 初心者向け
#1,813 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
19

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

spring-cloud/spring-cloud-commons のほかの issue

spring-cloud/spring-cloud-commons の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。