Skip to content

Neo4jTemplate.saveAllAs throws NullPointerException when given empty list #2544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cberes opened this issue May 27, 2022 · 0 comments
Closed
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@cberes
Copy link
Contributor

cberes commented May 27, 2022

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.

cberes added a commit to cberes/spring-data-neo4j that referenced this issue May 27, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2022
cberes added a commit to cberes/spring-data-neo4j that referenced this issue May 27, 2022
cberes added a commit to cberes/spring-data-neo4j that referenced this issue May 27, 2022
michael-simons added a commit that referenced this issue May 30, 2022
When an empty collection is passed to imperative and reactive `saveAllAs` variants a common element type can't be computed. We did not check for this scenario correctly and failed with a NPE. The introduction of a marker class fixes #2544 

Co-authored-by: Michael Simons <[email protected]>
michael-simons added a commit that referenced this issue May 30, 2022
When an empty collection is passed to imperative and reactive `saveAllAs` variants a common element type can't be computed. We did not check for this scenario correctly and failed with a NPE. The introduction of a marker class fixes #2544

Co-authored-by: Michael Simons <[email protected]>
michael-simons added a commit that referenced this issue May 30, 2022
michael-simons added a commit that referenced this issue May 30, 2022
michael-simons added a commit that referenced this issue May 30, 2022
@michael-simons michael-simons mentioned this issue Jan 4, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants