RedisIndexedSessionRepository nullability issues
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java at setRedisSessionMapper and getSession. Check the mapper's nullability against the nullable result handled by getSession, then verify that the Kotlin custom mapper in the issue compiles while invalid sessions can still return null.
Written by the indexing model from the issue text.
Description
Describe the bug
When upgrading to spring-session-data-redis 4.1.0 we can no longer call org.springframework.session.data.redis.RedisIndexedSessionRepository#setRedisSessionMapper to set a custom session mapper in Kotlin.
This is because the signature of redisSessionMapper expects the BiFunction to return a non-null MapSession, whereas before this was not the case (the result could be a null session).
Observing org.springframework.session.data.redis.RedisIndexedSessionRepository#getSession we see that the result of the BiFunction is expected to be a nullable value:
private @Nullable RedisSession getSession(String id, boolean allowExpired) {
// omitted for brevity
MapSession loaded = this.redisSessionMapper.apply(id, entries);
if (loaded == null || (!allowExpired && loaded.isExpired())) {
return null;
}
// omitted for brevity
}
To Reproduce
The custom mapper below fails to compile in Kotlin because it returns null when loading an invalid session causes an IllegalStateException to be thrown:
@Bean
fun redisSessionRepositoryCustomizer() =
SessionRepositoryCustomizer<RedisIndexedSessionRepository> { redisSessionRepository ->
val delegate = RedisSessionMapper()
redisSessionRepository.setRedisSessionMapper { sessionId, map ->
try {
delegate.apply(sessionId, map)
} catch (_: IllegalStateException) {
redisSessionRepository.sessionRedisOperations.delete("${sessionDataRedisProperties.namespace}:sessions:$sessionId")
null
}
}
}
Expected behavior
The custom mapper above should compile in Kotlin.
Sample
N/A
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 1.2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 55
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-session
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
spring-projects/spring-session#3477 · 2 comments · 2 reactions ·
-
status: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
spring-projects/spring-session#1729 · 2 comments · 1 reaction ·
-
in: build type: task
spring-projects/spring-session#3958 · 1 comment · 1 assignee ·
-
status: waiting-for-triage type: bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
spring-projects/spring-session#3827 · 1 comment ·
-
status: waiting-for-triage type: bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
spring-projects/spring-session#3755 · 5 comments · 1 reaction ·
All issues in spring-projects/spring-session
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100