Skip to content
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

Kotlin does not consider @Nullable annotation from RedisOperations #2208

Open
wants to merge 1 commit into
base: 2.7.x
Choose a base branch
from

Conversation

ghoonch4
Copy link

@ghoonch4 ghoonch4 commented Dec 5, 2021

There is a type issue in Kotlin due to the missing @Nullable annotation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 5, 2021
@mp911de
Copy link
Member

mp911de commented Dec 9, 2021

Nullability constraints are typically inherited for methods that specify e.g. @Nullable on the interface level.

@Nullable
<T> T execute(SessionCallback<T> session);

Do you have further pointers regarding that issue towards how Kotlin considers nullability annotation rules?

Paging @sdeleuze

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Dec 9, 2021
@ghoonch4
Copy link
Author

ghoonch4 commented Dec 9, 2021

@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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 9, 2021
@mp911de
Copy link
Member

mp911de commented Dec 10, 2021

Thanks a lot, that's quite interesting and likely a subject to happen in other places as well that use nullability annotations on interfaces.

@mp911de mp911de added the for: team-attention An issue we need to discuss as a team to make progress label Dec 10, 2021
@mp911de mp911de changed the title Set the RedisTemplate#execute(SessionCallback) method to nullable. Kotlin does not consider @Nullable annotation from RedisOperations Dec 10, 2021
@mp911de
Copy link
Member

mp911de commented Dec 10, 2021

Seems that this is a general issue: spring-projects/spring-framework#20424

@ghoonch4
Copy link
Author

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!

@mp911de
Copy link
Member

mp911de commented Dec 13, 2021

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.

@mp911de mp911de added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we need to discuss as a team to make progress status: feedback-provided Feedback has been provided type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants