File tree 4 files changed +23
-2
lines changed
main/java/org/springframework/data/neo4j/core
test/java/org/springframework/data/neo4j/core
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) {
310
310
}
311
311
312
312
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 );
314
315
if (entityMetaData .isUsingInternalIds () || entityMetaData .hasVersionProperty ()
315
316
|| entityMetaData .getDynamicLabelsProperty ().isPresent ()) {
316
317
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) {
306
306
}
307
307
308
308
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 );
310
311
311
312
if (entityMetaData .isUsingInternalIds () || entityMetaData .hasVersionProperty ()
312
313
|| entityMetaData .getDynamicLabelsProperty ().isPresent ()) {
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ final class TemplateSupport {
42
42
@ Nullable
43
43
static Class <?> findCommonElementType (Iterable <?> collection ) {
44
44
45
+ if (collection == null ) {
46
+ return null ;
47
+ }
48
+
45
49
List <Class <?>> allClasses = StreamSupport .stream (collection .spliterator (), true )
46
50
.filter (o -> o != null )
47
51
.map (Object ::getClass ).collect (Collectors .toList ());
Original file line number Diff line number Diff line change 18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
20
20
import java .util .Arrays ;
21
+ import java .util .Collections ;
21
22
22
23
import org .junit .jupiter .api .Test ;
23
24
@@ -76,6 +77,20 @@ void shouldNotFailWithNull() {
76
77
assertThat (type ).isNotNull ().isEqualTo (A .class );
77
78
}
78
79
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
+
79
94
@ Test
80
95
void shouldFindCommonElementTypeOfHumongousCollection () {
81
96
You can’t perform that action at this time.
0 commit comments