JsonMapper rejects JSON arrays over 1000 elements: hardcoded limit, silent failure in Spring Cloud Stream
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java, kafka, spring-boot
- 領域
- backend
調査の方向性
Start with the linked upstream commit, then read ContextFunctionCatalogAutoConfiguration.JsonMapperConfiguration#jackson, which unconditionally registers CollectionLimitModule, and LimitedCollectionDeserializer where MAX_ITEMS = 1000 is hardcoded. From there follow JsonMessageConverter#convertFromInternal, which swallows the failure at DEBUG and returns null. A fix means a configurable bound (with an off switch), a WARN or MessageConversionException instead of null, and tests reproducing the 1001-element Payload sample.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Since 5.1.0 (and 5.0.6), the auto-configured Jackson JsonMapper rejects any JSON array with more than 1000 elements. The limit is hardcoded, and in Spring Cloud Stream the failure is silent, so it is hard to find.
Versions: Spring Cloud Function 5.1.0, Spring Cloud Stream 5.1.0 with the Kafka binder, Spring Boot 4.2.0, Jackson 3.3.0.
Where it happens:
ContextFunctionCatalogAutoConfiguration.JsonMapperConfiguration#jacksonalways registersCollectionLimitModule.LimitedCollectionDeserializerthrowsIllegalStateException: Collection size exceeds limit of 1000whenMAX_ITEMS = 1000is exceeded. There is no property to change or disable it.JsonMessageConverter#convertFromInternalcatches the exception, logs it only at DEBUG and returnsnull.- The function then receives the raw
byte[]payload and fails withClassCastException: class [B cannot be cast to class MyDto. In our setup the message then goes to the DLQ after retries.
This hit us in production after upgrading to Spring Boot 4.2. One of our consumers receives a valid JSON document with a list of about 3700 items. It worked before the upgrade and fails with 5.1.0. The only visible error was the ClassCastException, which points away from the real cause.
The upstream change that added the limit: Ensure deserialization of JSON arrays/collections is bounded.
We understand why a bound is useful. Would it be possible to:
- Make the limit configurable, for example with a
spring.cloud.function.*property, including a way to turn it off. - Report the conversion failure at WARN level or as a
MessageConversionException, instead of returningnulland letting the function fail with aClassCastException.
As a workaround we can declare our own org.springframework.cloud.function.json.JsonMapper bean, since the auto-configured one is @ConditionalOnMissingBean. That also drops the other defaults of the auto-configured mapper, so a property would be much simpler.
Sample
record Payload(List<Integer> items) {}
@Autowired
org.springframework.cloud.function.json.JsonMapper jsonMapper;
// JSON with 1001 elements: {"items":[0,1,2,...,1000]}
jsonMapper.fromJson(json.getBytes(StandardCharsets.UTF_8), Payload.class);
// tools.jackson.databind.DatabindException: Collection size exceeds limit of 1000
In a stream application, a Consumer<Payload> bean bound to a Kafka topic shows the same problem as a ClassCastException.
Thank you!
- 主要言語
- Java
- スター
- 1.1k
- フォーク
- 655
- 平均マージ
- 4時間 54分
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
spring-cloud/spring-cloud-function のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
spring-cloud/spring-cloud-function#1542 ·
メンテナーはふだん 1 日以内に返信
-
GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invoker対応中かも @zemiles が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 32/100
spring-cloud/spring-cloud-function#1544 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Kotlin function wrapper treats empty input as no input対応中かも @seonwooj0810 が今日担当しました。 オープン5.0.x backport bug
難易度 3/5 半日 初心者へのやさしさ 30/100
spring-cloud/spring-cloud-function#1537 ·
メンテナーはふだん 1 日以内に返信
-
5.0.x backport bug
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
spring-cloud/spring-cloud-function#1536 ·
メンテナーはふだん 1 日以内に返信
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths対応中かも @seonwooj0810 が 1 日前に担当しました。 オープン5.0.x backport bug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
spring-cloud/spring-cloud-function#1535 ·
メンテナーはふだん 1 日以内に返信
spring-cloud/spring-cloud-function の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
aphtech/brailleblaster#209 ·
メンテナーはふだん 1 日以内に返信
-
payers.csv writes QOLS_AVG as NaN for every payer that had no members対応中かも @DG47 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
synthetichealth/synthea#1797 ·
メンテナーはふだん 19 日以内に返信
-
build enhancement security
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
midhunhk/lib-aeapps#54 ·