Skip to content
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

NPE when projecting to an interface and using StringBasedAggregation #4839

Open
fdutton opened this issue Nov 20, 2024 · 5 comments · May be fixed by #4841
Open

NPE when projecting to an interface and using StringBasedAggregation #4839

fdutton opened this issue Nov 20, 2024 · 5 comments · May be fixed by #4841
Assignees
Labels
type: bug A general bug

Comments

@fdutton
Copy link

fdutton commented Nov 20, 2024

  1. AbstractMongoQuery.execute() calls ReturnedInterface.getTypeToRead()
  2. ReturnedInterface.getTypeToRead() returns null when the query's result is a closed projection
  3. AbstractMongoQuery.execute() calls StringBasedAggregation.execute()
  4. StringBasedAggregation.execute() calls StringBasedAggregation.isSimpleReturnType() and passes null as the targetType
  5. StringBasedAggregation.isSimpleReturnType() calls MongoSimpleTypes.HOLDER.isSimpleType()
  6. MongoSimpleTypes.HOLDER.isSimpleType() raises a NullPointerException by attempting to invoke type.isEnum() when type is null

This does not happen when projecting to a class.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 20, 2024
@mp911de
Copy link
Member

mp911de commented Nov 21, 2024

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Nov 21, 2024
@fdutton
Copy link
Author

fdutton commented Nov 21, 2024

I already diagnosed the problem and attempted to describe what is happening step-by-step. I think the root cause is in ReturnedInterface.getTypeToRead as it returns null under certain conditions when it should return a Class that represents the interface used in the projection.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 21, 2024
@mp911de
Copy link
Member

mp911de commented Nov 22, 2024

I already diagnosed the problem and attempted to describe what is happening step-by-step.

I appreciate that you understand the issue. In such a case, care to submit a pull request?

If not, then I'd like to understand the issue too and the way you understand things might be very different that other people understand them.

fdutton pushed a commit to fdutton/spring-data-mongodb that referenced this issue Nov 22, 2024
…ting to an interface and using StringBasedAggregation
@fdutton
Copy link
Author

fdutton commented Nov 22, 2024

The best I can do at the moment is provide a failing unit-test. I attempted a fix but there are other issues preventing interface-based projections and I don't know enough about the inner workings of Spring Data Mongo. In my opinion, the root cause of this issue lies within spring-data-commons but a fix there would probably break some other implementation.

#4840

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 25, 2024
@christophstrobl
Copy link
Member

@fdutton thanks for the testcase.

christophstrobl pushed a commit that referenced this issue Nov 25, 2024
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
4 participants