-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Kotlin does not consider @Nullable
annotation from RedisOperations
#2208
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
Conversation
Nullability constraints are typically inherited for methods that specify e.g. @Nullable
on the interface level.
spring-data-redis/src/main/java/org/springframework/data/redis/core/RedisOperations.java
Lines 75 to 76 in b67f133
Do you have further pointers regarding that issue towards how Kotlin considers nullability annotation rules?
Paging @sdeleuze
@mp911de I tried it based on your comments. In Java, as you said, it inherits the @Nullable
annotation specified on the interface level, but in Kotlin it is not.
Here's my situation:
스크린샷 2021年12月10日 오전 1 18 55
Thanks a lot, that's quite interesting and likely a subject to happen in other places as well that use nullability annotations on interfaces.
@Nullable
annotation from RedisOperations
(追記ここまで)
Seems that this is a general issue: spring-projects/spring-framework#20424
I understand that this is a general issue that can happen in other places as well.
For one more reason, for code consistency, I think it's better to add @Nullable
annotation to RedisTemplate#execute(SessionCallback)
method. The RedisTemplate#execute(RedisCallback)
method, like the RedisTemplate#execute(SessionCallback)
method, is annotated with @Nullable
at the interface level, but is annotated with @Nullable
once again. I think this difference can be confusing. I wonder what you think!
I wonder why Kotlin considers JSR-305 so much different than Java tooling does. Regardless, if a method is @Nullable
on the interface level, then it is expected to adhere to that contract in the implementation method. The only exception is if the implementation method is annotated with @NonNull
. The ...Operations
interfaces are designed to be the entry-point and to not use the concrete implementation directly unless necessary.
The annotation on <T> T execute(RedisCallback<T> action)
is an oversight and comes from the initial introduction of nullability annotations. <T> T execute(RedisCallback<T> action, boolean exposeConnection)
is annotated with @Nullable
while it is not a method that is exposed on the interface.
Uh oh!
There was an error while loading. Please reload this page.
There is a type issue in Kotlin due to the missing
@Nullable
annotation.