File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed
main/java/org/springframework/data/neo4j/core
test/java/org/springframework/data/neo4j/core Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -310,7 +310,8 @@ public <T> List<T> saveAll(Iterable<T> instances) {
310310 }
311311
312312 Class <T > domainClass = (Class <T >) TemplateSupport .findCommonElementType (entities );
313- Neo4jPersistentEntity entityMetaData = neo4jMappingContext .getPersistentEntity (domainClass );
313+ Assert .notNull (domainClass , "Could not determine common domain class to save." );
314+ Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getPersistentEntity (domainClass );
314315 if (entityMetaData .isUsingInternalIds () || entityMetaData .hasVersionProperty ()
315316 || entityMetaData .getDynamicLabelsProperty ().isPresent ()) {
316317 log .debug ("Saving entities using single statements." );
Original file line number Diff line number Diff line change @@ -306,7 +306,8 @@ public <T> Flux<T> saveAll(Iterable<T> instances) {
306306 }
307307
308308 Class <T > domainClass = (Class <T >) TemplateSupport .findCommonElementType (entities );
309- Neo4jPersistentEntity entityMetaData = neo4jMappingContext .getPersistentEntity (domainClass );
309+ Assert .notNull (domainClass , "Could not determine common domain class to save." );
310+ Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getPersistentEntity (domainClass );
310311
311312 if (entityMetaData .isUsingInternalIds () || entityMetaData .hasVersionProperty ()
312313 || entityMetaData .getDynamicLabelsProperty ().isPresent ()) {
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ final class TemplateSupport {
4242 @ Nullable
4343 static Class <?> findCommonElementType (Iterable <?> collection ) {
4444
45+ if (collection == null ) {
46+ return null ;
47+ }
48+
4549 List <Class <?>> allClasses = StreamSupport .stream (collection .spliterator (), true )
4650 .filter (o -> o != null )
4751 .map (Object ::getClass ).collect (Collectors .toList ());
Original file line number Diff line number Diff line change 1818import static org .assertj .core .api .Assertions .assertThat ;
1919
2020import java .util .Arrays ;
21+ import java .util .Collections ;
2122
2223import org .junit .jupiter .api .Test ;
2324
@@ -76,6 +77,20 @@ void shouldNotFailWithNull() {
7677 assertThat (type ).isNotNull ().isEqualTo (A .class );
7778 }
7879
80+ @ Test
81+ void shouldNotFailWithNullInput () {
82+
83+ Class <?> type = TemplateSupport .findCommonElementType (null );
84+ assertThat (type ).isNull ();
85+ }
86+
87+ @ Test
88+ void shouldNotFailWithEmptyInput () {
89+
90+ Class <?> type = TemplateSupport .findCommonElementType (Collections .emptyList ());
91+ assertThat (type ).isNull ();
92+ }
93+
7994 @ Test
8095 void shouldFindCommonElementTypeOfHumongousCollection () {
8196
You can’t perform that action at this time.
0 commit comments