Skip to content

Commit 4172d40

Browse files
committed
spring-projectsGH-2544 Neo4jTemplate.saveAllAs returns emptyList when given empty iterable.
1 parent 376ad70 commit 4172d40

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

+4
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
520520

521521
Assert.notNull(resultType, "ResultType must not be null!");
522522

523+
if (!instances.iterator().hasNext()) {
524+
return Collections.emptyList();
525+
}
526+
523527
Class<?> commonElementType = TemplateSupport.findCommonElementType(instances);
524528

525529
if (resultType.isAssignableFrom(commonElementType)) {

src/test/java/org/springframework/data/neo4j/integration/imperative/Neo4jTemplateIT.java

+7
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,13 @@ void saveAllAsWithClosedProjectionShouldWork() {
795795
assertThat(people).allMatch(p -> p.getAddress() != null);
796796
}
797797

798+
@Test
799+
void saveAllAsWithEmptyList() {
800+
List<ClosedProjection> projections = neo4jTemplate.saveAllAs(Collections.emptyList(), ClosedProjection.class);
801+
802+
assertThat(projections).isEmpty();
803+
}
804+
798805
@Test
799806
void updatingFindShouldWork() {
800807
Map<String, Object> params = new HashMap<>();

0 commit comments

Comments
 (0)