JsonMapper rejects JSON arrays over 1000 elements: hardcoded limit, silent failure in Spring Cloud Stream
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/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, kafka, spring-boot
- Lĩnh vực
- backend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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!
- Ngôn ngữ chính
- Java
- Star
- 1.1k
- Fork
- 655
- Merge trung bình
- 4 giờ 54 phút
- Pull request đã merge (30 ngày)
- 10
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-function
-
ClassCastException with spring-cloud-function 4.3.6 when a field of type Set is deserializedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
spring-cloud/spring-cloud-function#1542 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invokerCó thể đã có người làm @zemiles đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 32/100
spring-cloud/spring-cloud-function#1544 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Kotlin function wrapper treats empty input as no inputCó thể đã có người làm @seonwooj0810 đã nhận hôm nay. Đang mở5.0.x backport bug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 30/100
spring-cloud/spring-cloud-function#1537 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Default JSON mapper collection limit is hard-coded and replaces all collection deserializationĐang mở5.0.x backport bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
spring-cloud/spring-cloud-function#1536 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion pathsCó thể đã có người làm @seonwooj0810 đã nhận 1 ngày trước. Đang mở5.0.x backport bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
spring-cloud/spring-cloud-function#1535 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của spring-cloud/spring-cloud-function
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
aphtech/brailleblaster#209 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
payers.csv writes QOLS_AVG as NaN for every payer that had no membersCó thể đã có người làm @DG47 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
synthetichealth/synthea#1797 ·
Maintainer thường phản hồi trong vòng 19 ngày
-
build enhancement security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
midhunhk/lib-aeapps#54 ·