Add note to documentation when using Spring integration and Optional values
See original GitHub issueThe chapter on null values states that:
In case the loader returns
null
and this should not lead to an exception the following options exist: Always return a non-null object and include a predicate for thenull
case, use a list or Java 8Optional
.
However, when using the Spring Framework integration and values are of class Optional
, since Spring unwraps the value in CacheAspectSupport
, an NPE will be thrown unless permitNullValues
is set to true
.
I think this is worth mentioning in the Spring chapter. Let me know what you think. I can open a PR to add this to the docs. I haven’t done so because I don’t know if https://github.com/cache2k/cache2k/issues/135 will conflict with Spring or will make that consideration unnecessary.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Spring Integration Reference Guide
Mapping Method Arguments to a Message ... You can use start.spring.io to generate a basic project (add integration as dependency) or follow one...
Read more >Spring integration annotation Java 8 Optional Incorrect Handling
Release and Java 8, the problem is that Spring is wrapping Optional payload into new Optional objects as many times as I am...
Read more >spring-projects/spring-integration-aws - GitHub
The SqsMessageDrivenChannelAdapter exposes all SimpleMessageListenerContainer attributes to configure, and an important one of them is messageDeletionPolicy , ...
Read more >Documentation for the spring Generator
Property, Value, Notes ... Option, Description, Values, Default ... hateoas, Use Spring HATEOAS library to allow adding HATEOAS links, false.
Read more >Spring Integration - DZone Refcardz
An Inbound Channel Adapter can invoke methods on a Spring-managed bean and send non-null values to a Message Channel as Spring Integration Messages....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using
permitNullValues(true)
and using the null support in cache2k is the optimization for Spring, because that means there is no additional object wrapper needed.Just looking on cache2k itself there is no runtime difference whether this is enabled or not. The flag is present to be aware of the difference in behavior. Historically null support was always enabled. But analyzing code using the cache revealed that developers think that
null
means no cached value is present. Typical cache aside code looked like:As soon
null
is a legal value in the cache, that code is wrong.With the default settings cache2k is compatible with other caches, w.r.t.
null
. But if you want it and know what you are doing, you can enable it.Releasing 1.4 and closing this issue, in the hope that nothing is left to do. Please feel free any time to comment here or raise another issue if there is still a problem.