-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
@Cacheable
throws NullPointerException
when RuntimeException
is thrown inside annotated code
#33492
Comments
@Cacheable
throws NullPointerException
when RuntimeException
is thrown inside annotated code
If your exception is a subtype of |
Hi @simonbasle , I think I don't understand your proposal. In the project we have a controller advice that catches our business runtime exceptions. The thing is, that if I throw What kind of error handling are you proposing in this case? Thanks for your time |
@drg2000 I see, the NPE's message is important context. I'll investigate further, but if you can provide a unit test or simple reproducer it would help tremendously. |
Hi @simonbasle and sorry for the late reply, been kind of busy lately. I've created a small spring project which replicates the issue. You just can launch the Application test or run the app and Thanks for your time |
Thanks for the reproducing project, it helped me verify that my tentative fix was working for your case 👍 |
Hi @simonbasle, thanks for your help! It would be helpful If you could post a comment here once the fix is done, just out of curiosity to see which was the solution. Thanks for your time. |
Hi, I have a piece of code in a reactive project that looks something like that (similar code for demo purposes):
I have a specific exception, but it basically extends from
RuntimeException
.I've been debugging a little, and it seems that
CacheAspectSupport
had a piece of code added in commit 8974da2 that changedReactiveCachingHandler
from this:to this:
The thing is, first evaluate call before the method execution sets the contexts.processed to true, and after my method throws the runtime exception, is caught by this
onErrorResume
, which calls evaluate withcacheHit
set tonull
, andreturns
null
.Is this an actual issue or I am missing something?
As of now I've done a couple of extra tests, and it seems that I cannot throw a
RuntimeException
. I have two CacheManagers configured in my Spring Boot project, one for Caffeine and the other one for Redis. This only happens when using theRedisCacheManager
as seen above.I think this might be because
CaffeineCache
implementation ofCache
returnsnull
when the element is not present whereasRedisCache
implementation returns a cachedFuture.Thanks in advance for any help provided!
The text was updated successfully, but these errors were encountered: