question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add note to documentation when using Spring integration and Optional values

See original GitHub issue

The 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 the null case, use a list or Java 8 Optional.

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:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cruftexcommented, Aug 25, 2020

So in Spring permitNullValues(false) would be an optimisation of sorts?

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:

  V value = cache.get(key);
  if (value == null) {
    value = ....;
    cache.put(key, value);
  }

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.

0reactions
cruftexcommented, Sep 12, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found