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

Refine null-safety with NullAway build-time checks #32475

Closed
sdeleuze opened this issue Mar 18, 2024 · 2 comments
Closed

Refine null-safety with NullAway build-time checks #32475

sdeleuze opened this issue Mar 18, 2024 · 2 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Mar 18, 2024

As discussed with the JSpecify working group, the goal of this issue is to introduce null-safety checks at build-time using NullAway and the related Error Prone Gradle plugin and refine Spring null-safety annotations accordingly.

Unlike #28797, the purpose of this issue is to continue to leverage JSR 305 annotations. That said, such formal build-time checks will likely ease a potential transition to a different null-safety mechanism (JSpecify or at Java platform level) in the future.

See this draft commit that enables those null-checks on spring-core and generates 41 errors that will likely to lead null-safety refinements.

@sdeleuze sdeleuze added the type: enhancement A general enhancement label Mar 18, 2024
@sdeleuze sdeleuze added this to the 6.2.0-M1 milestone Mar 18, 2024
@sdeleuze sdeleuze self-assigned this Mar 18, 2024
jhoeller added a commit that referenced this issue Mar 18, 2024
jhoeller added a commit that referenced this issue Mar 18, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 19, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 19, 2024
This commit introduces null-safety checks for spring-core at build-time
in order to validate the consistency of Spring null-safety annotations
and generate errors when inconsistencies are detected during a build
(similar to what is done with Checkstyle).

In order to make that possible, this commit also introduces a new
org.springframework.lang.Contract annotation inspired from
org.jetbrains.annotations.Contract, which allows to specify semantics
of methods like Assert#notNull in order to prevent artificial
additional null checks in Spring Framework code base.

This commit only checks org.springframework.core package, follow-up
commits will also extend the analysis to other modules, after related
null-safety refinements.

See spring-projectsgh-32475
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 20, 2024
sdeleuze added a commit that referenced this issue Mar 20, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 22, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 22, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 22, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 22, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 25, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 26, 2024
This commit refines the null-safety in:
 - spring-jdbc
 - spring-r2dbc
 - spring-orm
 - spring-beans
 - spring-aop

See spring-projectsgh-32475
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 26, 2024
This commit enables null-safety build-time checks in:
 - spring-jdbc
 - spring-r2dbc
 - spring-orm
 - spring-beans
 - spring-aop

See spring-projectsgh-32475
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 26, 2024
This commit refines the null-safety in all remaining modules
except spring-test.

See spring-projectsgh-32475
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 26, 2024
This commit enables null-safety build-time checks in
all remaining modules except spring-test.

See spring-projectsgh-32475
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 26, 2024
sdeleuze added a commit that referenced this issue Apr 5, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Apr 5, 2024
This commit reverts some null-safety changes which make sense
on main but are too impactful for 6.1.x for Kotlin developers
using -Xjsr305=strict.

See spring-projectsgh-32475
@leikingo
Copy link

Hi.
I stumbled upon this issue and esp. 4c77350 for the class org.springframework.util.Assert while trying to get rid of some null warnings in IntelliJ.

Is there a specific reason why for example the method hasText does not have a contract @Contract(null, _ -> fail) ?

I'm often using only hasText for incoming @Nullable strings to ensure a non-null value afterwards, but unfortunately this does not eliminate the warning. Although hasText would also throw an exception in case of null. For now I need to add also notNull or use 'external contract annotations' in IntelliJ. IntelliJ's external annotations are a bit cumbersome, since it is not possible to do it globally (as far as I know at least). It would be great if those @Contract annotations could be added to the remaining Assert methods as well to avoid this in the future. (hopefully they would then also be recognized by IntelliJ)

@sbrannen
Copy link
Member

Hi @leikingo,

This issue was closed 6 months ago for 6.2 M1.

Can you please create a new issue to address your concerns about missing @Contract declarations in Assert?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants