Skip to content

Neo4jTemplate.saveAllAs throws NullPointerException when given empty list #2544

@cberes

Description

@cberes

Neo4jTemplate.saveAllAs(Iterable<T>, Class<R>) throws NullPointerException when given an empty list, for example

neo4jTemplate.saveAllAs(emptyList(), Projection.class);

throws the following Exception

java.lang.NullPointerException
 at java.base/java.lang.Class.isAssignableFrom(Native Method)
 at org.springframework.data.neo4j.core.Neo4jTemplate.saveAllAs(Neo4jTemplate.java:525)
 at org.springframework.data.neo4j.integration.imperative.Neo4jTemplateIT.saveAllAsWithEmptyList(Neo4jTemplateIT.java:800)

TemplateSupport.findCommonElementType returns null, which causes the NPE when null is passed to Class.isAssignableFrom.

I could understand a NPE being thrown when null is passed in, but it seems unusual to throw a NPE in this case. Perhaps an empty list should be returned instead.

I'll open a pull request with a test and possible solution in a moment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions