Skip to content

Refine null-safety for additional Assert methods #33530

@leikingo

Description

@leikingo

I saw the work being done to add @Contract annotations for null-safety analysis (#32475).

Having a look at the updates to org.springframework.util.Assert methods, I wonder why for example hasText was not annotated with @Contract(null,_ -> fail), although hasText would also throw an exception in case of null.

I'm often using only Assert.hasText for incoming @Nullable strings to ensure a non-null value afterwards. Unfortunately IntelliJ does not recognize this method correctly, like it does for Assert.notNull.

For now I need to add another notNull check in the code or use 'external contract annotations' in IntelliJ, which is quite cumbersome.

It would be great if @Contract annotations could be added to the remaining Assert methods as well to avoid this in the future hoping that they would then also be recognized by IntelliJ correctly).

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions