-
Notifications
You must be signed in to change notification settings - Fork 682
SpelEvaluator.evaluate(…)
fails with NullPointerException
when an expression yields a null
value
#2904
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
Comments
Can you please provide a reproducer and attach the stack trace so we can better understand where the issue comes from? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
I have provided a test case in this repository: https://github.com/rogeriomgatto/minimal-test-case-1577 The following tests reproduce the bugs, the other tests are just to confirm everything else is ok:
I also uploaded my proposed fixes, and can provide pull requests, I just don't know how to proceed since one PR depends on the other. Should I just open them? To test with the proposed changes, clone both repositories, checkout branch |
Forgot the stack traces. |
Thanks a lot. The problem is being caused by |
SpelEvaluator.evaluate(…)
fails with NullPointerException
when an expression yields a null
value
Regarding the conversion issue, we never added conversion support to String-based queries. It would make sense to run binding values by the |
SpelEvaluator now iterates over the parameter map instead of using the Java 8 Stream API. Previously, expressions resulting in a null value failed in the collector as Java 8 streams require non-null values for map values. Closes #2904
SpelEvaluator now iterates over the parameter map instead of using the Java 8 Stream API. Previously, expressions resulting in a null value failed in the collector as Java 8 streams require non-null values for map values. Closes #2904
SpelEvaluator now iterates over the parameter map instead of using the Java 8 Stream API. Previously, expressions resulting in a null value failed in the collector as Java 8 streams require non-null values for map values. Closes #2904
Thanks for the fix!
For string queries in general, there is conversion support when using "regular" parameter binding, just not for SpEL expressions, right? In my test cases, regular parameters of type |
Yes, please. |
I'm trying to use SpEL to bind parameter values from DTOs like this, in a JDBC repository:
When any property is
null
, an NPE is thown inorg.springframework.data.repository.query.SpelEvaluator
because it usesCollectors.toMap
and it doesn't supportnull
values.Also, there is no convertion to database types, for example an
Instant
value isn't converted tojava.sql.Timestamp
and sql execution fails.I managed to fix both issues locally (I think):
spring-data-commons
SpelEvaluator
to gatherTypeInformation
usingExpression::getValueTypeDescriptor
evaluate
that returns a vo with both value andTypeInformation
Collectors.toMap
spring-data-jdbc
:StringBasedJdbcQuery
to use the new method fromSpelEvaluator
TypeInformation
throughconvertAndAddParameter
instead of adding directly to theMapSqlParameterSource
How should I proceed to send the PRs, since they involve two projects?
The text was updated successfully, but these errors were encountered: