-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Introduce null-safety of Spring Framework API [SPR-15540] #20099
Comments
Sébastien Deleuze commented After a deeper look and discussing on the KT-10942, here is what I found. First, this issue is not only interesting for Kotlin users but also for all Java developers since IntelliJ IDEA supports JSR 305 annotations provided by findbugs package as well as Eclipse. Second, while @Documented
@Nonnull
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface NonNullApiByDefault {
} IDEA already supports these meta annotations so that could enable us to move forward even before Kotlin support that. Andrey Breslav has expressed his interest in supporting these meta-annotations in Kotlin so that could be a nice outcome. I am going to create a branch right now to experiment on this. We should have shortly some news from the Kotlin side. |
Sébastien Deleuze commented Work in progress commit : master...sdeleuze:null-safety My goal is to reach a state where if have processed all Spring Framework modules Javadoc nullability related comments and applied the matching I will perform additional tests with IDEA and Eclipse to see how these annotations are taken in account in Java ASAP. |
Sébastien Deleuze commented After some tests I confirm that works with IntelliJ which reports warnings if Juergen Hoeller Could you please have a quick look on the modules I did on this branch to give me your advice, especially to validate the |
Sébastien Deleuze commented I am approaching a stage where I will be able to merge in master. After discussing with Juergen Hoeller, we have chosen to leverage JSR 305 meta-annotations in 2 new Spring annotations. This seems the right tradeoff since it avoid us to directly expose dormant JSR 305 annotations (they could potentially change), give us the possibility to add additional meta-annotation later if needed, avoid to spread to JSR 305 with provided scope "trick" across all other Spring projects while IntelliJ (and Kotlin) will be able to recognize them without any kind of Spring specific support. We intend to use the same strategy on Reactor, and possibly other Spring projects. For package level: package org.springframework.lang;
@Documented
@Nonnull
@Target({ElementType.METHOD, ElementType.PARAMETER})
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface NonNullApi {
} Mostly for parameter or return value level: package org.springframework.lang;
@Documented
@javax.annotation.Nullable
@Target({ElementType.METHOD, ElementType.PARAMETER})
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {
} |
Sébastien Deleuze commented I am doing a last pass on the 1752 |
Sébastien Deleuze commented Merged in master via this commit. |
Sébastien Deleuze commented Unlike what I saw in my tests (not sure why), it seems IntelliJ does not recognize Spring |
Sébastien Deleuze commented Workaround for Spring projects developers: it is possible to make Spring |
Sébastien Deleuze commented After a useful discussion with Peter Gromov about JSR 305 and IDEA support for custom On Spring Framework side, I am going to update our @Documented
@TypeQualifierNickname
@Nonnull(when=MAYBE)
@Target({ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {
} IntelliJ IDEA 2017.1 next update will provide pre-configured support for Eclipse support nullable + non-null by default via configuration of the custom annotations so they will be able to leverage null-safety as well. I will add a documentation page providing more detail about null-safety for Spring developers and tooling vendors. |
Sébastien Deleuze commented See also related null-safety support on Reactor side, with a similar strategy for After Juergen Hoeller epic commit I am waiting feedbacks from other projects like Boot (#20201) or Data before resolving this issue. |
Sébastien Deleuze commented After another huge commit from Juergen Hoeller, nullability declaration is now extended to the field level as well. |
Sébastien Deleuze opened SPR-15540 and commented
The proposal brought by this issue is to make nullability of return values and parameters of Spring Framework API explicit via annotations, and leverage this information in Kotlin user Spring projects.
More details can be found in these 2 Square blog posts Rolling out @Nullable and Non-null is the default.
If at some points
@ParametersAreNonnullByDefault
is supported at package level, it seems it could be possible to add@Nullable
annotation only on nullable parameter and return values without bloating our code source with non-nullability annotations.Notice that the
com.google.code.findbugs:jsr305
dependency used is applied with aprovided
scope which seems to be enough to make it taken in account by Kotlin (without that Kotlin consider Java nullability as unknown). We need to check this would not create some classloader related issues.Reference URL: https://youtrack.jetbrains.com/issue/KT-10942
Issue Links:
@Nullable
on AbstractDestinationResolvingMessagingTemplate@Nullable
@SubscribeMapping
methods6 votes, 5 watchers
The text was updated successfully, but these errors were encountered: