Skip to content

Passing empty collections to derived finder methods lead to a NullPointerException. #2301

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
pelletier197 opened this issue Jun 21, 2021 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@pelletier197
Copy link

It seems to raise an exception when a provided parameter is an empty iterable (I have only tried with Set actually, but looking at the code that raises the error, it's likely the same thing with all Iterable<?>).

Given the following example (the database does not actually matter)

interface TestPersonRepository : Neo4jRepository<PersonEntity, String> {
    @Query(
        """
        MATCH (person:Person) WHERE person.email IN $${"emails"} OR person.name IN $${"names"}
        RETURN person
    """
    )
    fun findAllByNamesOrEmail(names: Set<String>, emails: Set<String>) : List<PersonEntity>
}

@Service
class TestService(
    private val repository: TestPersonRepository
) {
    init {
            repository.findAllByNamesOrEmail(emptySet(), setOf("potato"))
    }
}

I have the following stacktrace

Caused by: java.lang.IllegalArgumentException: Type must not be null!
	at org.springframework.util.Assert.notNull(Assert.java:201)
	at org.springframework.data.mapping.context.AbstractMappingContext.hasPersistentEntityFor(AbstractMappingContext.java:211)
	at org.springframework.data.neo4j.repository.query.Neo4jQuerySupport.convertParameter(Neo4jQuerySupport.java:190)
	at org.springframework.data.neo4j.repository.query.Neo4jQuerySupport.convertParameter(Neo4jQuerySupport.java:160)
	at org.springframework.data.neo4j.repository.query.StringBasedNeo4jQuery.lambda$bindParameters$8(StringBasedNeo4jQuery.java:218)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.data.neo4j.repository.query.StringBasedNeo4jQuery.bindParameters(StringBasedNeo4jQuery.java:213)
	at org.springframework.data.neo4j.repository.query.StringBasedNeo4jQuery.prepareQuery(StringBasedNeo4jQuery.java:180)
	at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.execute(AbstractNeo4jQuery.java:84)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
	// ...

The error actually seem to be in org.springframework.data.neo4j.core.TemplateSupport.findCommonElementType which returns a null class when the collection is empty.

I'm testing using the latest 6.1.2. Hope this helps!

@pelletier197 pelletier197 changed the title Bug: passing empty list as parameters raises an exception Bug: passing empty set as parameters raises an exception Jun 21, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 21, 2021
@michael-simons michael-simons self-assigned this Jun 22, 2021
@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 22, 2021
@michael-simons michael-simons changed the title Bug: passing empty set as parameters raises an exception Passing empty collections to derived finder methods may lead to a NullPointerException. Jun 22, 2021
@michael-simons michael-simons changed the title Passing empty collections to derived finder methods may lead to a NullPointerException. Passing empty collections to derived finder methods lead to a NullPointerException. Jun 22, 2021
@michael-simons
Copy link
Collaborator

Thanks @pelletier197 that helps a lot. It's an oversight from #2292. Luckily you caught this just before the impending release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants