Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ghoonch4 wants to merge 1 commit into spring-projects:2.7.x
base: 2.7.x
Choose a base branch
Loading
from ghoonch4:main

Conversation

Copy link

@ghoonch4 ghoonch4 commented Dec 5, 2021
edited
Loading

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

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
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
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
Copy link
Member

mp911de commented Dec 10, 2021

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

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!

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.

ghoonch4 reacted with thumbs up emoji

@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
Reviewers
No reviews
Assignees
No one assigned
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
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /