Skip to content

@Aggregation repository query method causes NullPointerException when the result is empty #3623

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
rootdavinalfa opened this issue Apr 11, 2021 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@rootdavinalfa
Copy link

Hello,

i'm have an issue regarding usage of Aggregation annotation on spring-data-mongodb

What i'm encounter is

Cannot invoke "org.bson.Document.isEmpty()" because "source" is null

This happen when collection empty (not have any document) but if have an document, i'm not encounter the error.

Here some snippet of code i'm using:

@Aggregation(
        "{" +
                "\$project: { maxid: {\$max: '\$_id'} }" +
                "}"
    )
    fun getMaxUnitID(): String?
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 11, 2021
@christophstrobl
Copy link
Member

Thanks for reporting - seems we miss a null check in AggregationUtils.

@christophstrobl christophstrobl removed the status: waiting-for-triage An issue we've not yet triaged label Apr 12, 2021
@christophstrobl christophstrobl self-assigned this Apr 12, 2021
@christophstrobl christophstrobl added the type: bug A general bug label Apr 12, 2021
christophstrobl added a commit that referenced this issue Apr 12, 2021
This commit fixes an issue where using a simple return type leads to NPE when the actual aggregation result does not contain any values.

Closes: #3623
@mp911de mp911de added this to the 3.0.9 (Neumann SR9) milestone Apr 13, 2021
@mp911de mp911de changed the title @Aggregation on spring-data-mongodb repository Null Pointer Exception when collection is empty @Aggregation repository query method causes NullPointerException when the result is empty Apr 13, 2021
mp911de added a commit that referenced this issue Apr 13, 2021
Use ObjectUtils for empty check.

See #3623
Original pull request: #3625.
mp911de pushed a commit that referenced this issue Apr 13, 2021
This commit fixes an issue where using a simple return type leads to NPE when the actual aggregation result does not contain any values.

Closes: #3623
Original pull request: #3625.
mp911de added a commit that referenced this issue Apr 13, 2021
Use ObjectUtils for empty check.

See #3623
Original pull request: #3625.
mp911de pushed a commit that referenced this issue Apr 13, 2021
This commit fixes an issue where using a simple return type leads to NPE when the actual aggregation result does not contain any values.

Closes: #3623
Original pull request: #3625.
mp911de added a commit that referenced this issue Apr 13, 2021
Use ObjectUtils for empty check.

See #3623
Original pull request: #3625.
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

Successfully merging a pull request may close this issue.

4 participants