Skip to content

GH-3857: Allow redisSessionMapper to return null MapSession - #3885

Open
arimu1 wants to merge 1 commit into
spring-projects:mainfrom
arimu1:GH-3857
Open

GH-3857: Allow redisSessionMapper to return null MapSession#3885
arimu1 wants to merge 1 commit into
spring-projects:mainfrom
arimu1:GH-3857

Conversation

@arimu1

@arimu1 arimu1 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

RedisIndexedSessionRepository and RedisSessionRepository already treat a null result from redisSessionMapper as a missing/unloadable session, but the BiFunction return type was declared non-null. That breaks Kotlin nullability when registering custom mappers that return null (for example after cleaning up a corrupt Redis hash).

This change annotates the mapper return type as @Nullable MapSession on the field and setter (and aligns RedisSessionMapper's BiFunction type for NullAway), matching existing runtime behavior.

Fixes #3857

Changes

  • Annotate redisSessionMapper field and setRedisSessionMapper with @Nullable MapSession return type in:
    • RedisIndexedSessionRepository
    • RedisSessionRepository
  • Align RedisSessionMapper with BiFunction<..., @Nullable MapSession> so the default assignment compiles under NullAway (implementation still never returns null)
  • Add unit tests that a mapper returning null yields findById(...) == null

Test plan

  • ./gradlew :spring-session-data-redis:test --tests RedisIndexedSessionRepositoryTests --tests RedisSessionRepositoryTests (Temurin 21)
  • DCO Signed-off-by on commit

…ssion

The BiFunction return type for redisSessionMapper was non-null, but
getSession/findById already treat a null mapper result as a missing
session. Annotate the return type as @nullable so Kotlin callers can
supply custom mappers that return null (for example when cleaning up
corrupt Redis hashes).

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RedisIndexedSessionRepository nullability issues

2 participants