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
Describe the bug
When upgrading to spring-session-data-redis 4.1.0 we can no longer call
org.springframework.session.data.redis.RedisIndexedSessionRepository#setRedisSessionMapperto set a custom session mapper in Kotlin.This is because the signature of
redisSessionMapperexpects theBiFunctionto return a non-nullMapSession, whereas before this was not the case (the result could be a null session).Observing
org.springframework.session.data.redis.RedisIndexedSessionRepository#getSessionwe see that the result of theBiFunctionis expected to be a nullable value:To Reproduce
The custom mapper below fails to compile in Kotlin because it returns null when loading an invalid session causes an
IllegalStateExceptionto 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