JsonMapper rejects JSON arrays over 1000 elements: hardcoded limit, silent failure in Spring Cloud Stream
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 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 分鐘
- 30 天內合併 PR
- 10
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 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 個 reaction ·
維護者通常 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 ·