Skip to content

Use @NullUnmarked and @NonNull where relevant on generic methods #35147

Closed as not planned
@sdeleuze

Description

@sdeleuze

Overview

As a workaround for #34911 that we can't support yet due to a NullAway temporary limitation, we should turn declarations like this one in JdbcOperations:

<T> @Nullable T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;

Into the following in order to keep unspecified nullness for the generic type and return value as we are not yet able to check this use case correctly for Spring Framework code or usage within Spring portfolio or user code with NullAway:

@NullUnmarked // Workaround for https://github.com/uber/NullAway/issues/1075
<T> T query(@NonNull String sql, @NonNull ResultSetExtractor<T> rse) throws DataAccessException;

Similar patterns in the Spring Framework codebase should be updated as well.

Once the related NullAway issue has been fixed, this workaround will be replaced (hopefully before Spring Framework 7 GA) by the idiomatic version via #34911:

<T extends @Nullable Object> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;

Related Issues

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions