Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

@Cacheable throwsNullPointerException whenRuntimeException is thrown inside annotated code #33492

Closed
Assignees
simonbasle
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug
Milestone
@drg2000

Description

@drg2000

Hi, I have a piece of code in a reactive project that looks something like that (similar code for demo purposes):

@Cacheable(value =RedisCacheNames.CONSTANT,cacheManager ="redisCacheManager")publicMono<String>get(Integerid) {returnMono.just("result")          .doOnSuccess(s ->throwException())  }privatevoidthrowException() {thrownewRuntimeException();  }

I have a specific exception, but it basically extends fromRuntimeException.

I've been debugging a little, and it seems thatCacheAspectSupport had a piece of code added in commit8974da2 that changedReactiveCachingHandler from this:

returnadapter.fromPublisher(Mono.fromFuture(cachedFuture).switchIfEmpty(Mono.defer(() -> (Mono)evaluate(null,invoker,method,contexts))).flatMap(v ->evaluate(Mono.justOrEmpty(unwrapCacheValue(v)),invoker,method,contexts)));

to this:

returnadapter.fromPublisher(Mono.fromFuture(cachedFuture).switchIfEmpty(Mono.defer(() -> (Mono)evaluate(null,invoker,method,contexts))).flatMap(v ->evaluate(Mono.justOrEmpty(unwrapCacheValue(v)),invoker,method,contexts)).onErrorResume(RuntimeException.class,ex -> {try {getErrorHandler().handleCacheGetError((RuntimeException)ex,cache,key);returnevaluate(null,invoker,method,contexts);}catch (RuntimeExceptionexception) {returnMono.error(exception);}}));

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 thisonErrorResume, which calls evaluate withcacheHit set tonull, and

if (contexts.processed) {returncacheHit;}

returnsnull.

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 aRuntimeException. 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 becauseCaffeineCache implementation ofCache returnsnull when the element is not present whereasRedisCache implementation returns a cachedFuture.

Thanks in advance for any help provided!

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp