Skip to content

Commit 99c025e

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

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
* @author Michael J. Simons
100100
* @author Philipp Tölle
101101
* @author Gerrit Meier
102+
* @author Corey Beres
102103
* @soundtrack Motörhead - We Are Motörhead
103104
* @since 6.0
104105
*/
@@ -520,6 +521,10 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
520521

521522
Assert.notNull(resultType, "ResultType must not be null!");
522523

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

525530
if (resultType.isAssignableFrom(commonElementType)) {

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

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
* @author Gerrit Meier
7777
* @author Michael J. Simons
7878
* @author Rosetta Roberts
79+
* @author Corey Beres
7980
*/
8081
@Neo4jIntegrationTest
8182
class Neo4jTemplateIT {
@@ -795,6 +796,13 @@ void saveAllAsWithClosedProjectionShouldWork() {
795796
assertThat(people).allMatch(p -> p.getAddress() != null);
796797
}
797798

799+
@Test // GH-2544
800+
void saveAllAsWithEmptyList() {
801+
List<ClosedProjection> projections = neo4jTemplate.saveAllAs(Collections.emptyList(), ClosedProjection.class);
802+
803+
assertThat(projections).isEmpty();
804+
}
805+
798806
@Test
799807
void updatingFindShouldWork() {
800808
Map<String, Object> params = new HashMap<>();

0 commit comments

Comments
 (0)