Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`YamlProcessor.getFlattenedMap` with `includeEmpty` returns a `null` key for an empty root mapping

Đang mở Phù hợp với người mới
#37,522 1 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

@erfannvb đang làm issue này rồi.

Từ ngày 20/10/2026.

Đá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
78/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
backend

Hướng nghiên cứu

Issue xác định YamlProcessor.getFlattenedMap và buildFlattenedMap, cùng với một trường hợp tái hiện cho mapping YAML gốc rỗng. Hãy đọc các phương thức đó và theo dõi cách đường dẫn gốc được xử lý khi includeEmpty là true; bài kiểm thử được cung cấp cho thấy kết quả mong đợi. Hoàn thành khi làm phẳng {} tạo ra một map rỗng không có khóa null, trong khi hành vi hiện có với các đầu vào khác vẫn được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status: waiting-for-triage

When getFlattenedMap(source, true, emptyValue) (added in 7.0.4 by #36197) is given an empty root map, such as a YAML document consisting of {}, it returns {null=emptyValue}. buildFlattenedMap stores an empty map under its parent path, and at the root that path is null.

class YamlProcessorEmptyRootTest {

	@Test
	void flattenedMapOfEmptyRootMappingHasNoNullKey() {
		List<Map<String, Object>> result = new FlatteningYamlProcessor("{}").flatten();

		assertThat(result).hasSize(1);
		assertThat(result.get(0)).doesNotContainKey(null);
	}

	static class FlatteningYamlProcessor extends YamlProcessor {

		FlatteningYamlProcessor(String yaml) {
			setResources(new ByteArrayResource(yaml.getBytes()));
		}

		List<Map<String, Object>> flatten() {
			List<Map<String, Object>> result = new ArrayList<>();
			process((properties, map) -> result.add(getFlattenedMap(map, true, "")));
			return result;
		}

	}

}

On 7.0.9 this fails with {null=""}. getFlattenedMap(map) returns {} for the same input.

The return type is Map<String, Object> in a @NullMarked package, so callers don't expect a null key. I'd expect an empty map: the root has no key under which the empty entry could be recorded.

This affects Spring Boot 4.1, whose OriginTrackedYamlLoader uses this method since spring-projects/spring-boot#48958. A {} document in an application.yml now gives an EnumerablePropertySource whose getPropertyNames() returns [null] (4.0.x returned []).

Ngôn ngữ chính
Java
Star
60.3k
Fork
38.7k
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
38

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-projects/spring-framework

Tất cả issue của spring-projects/spring-framework

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.