Skip to content

Declare flexible generic type nullability where relevant #35146

Closed as not planned
@sdeleuze

Description

@sdeleuze

Overview

Types like ResultSetExtractor<T> where the return type nullness depends on the generic type nullness should have their declaration improved to be more flexible as defined in JSpecify generic type documentation.

So the current declaration and similar patterns

@FunctionalInterface
public interface ResultSetExtractor<T> {
    @Nullable T extractData(ResultSet rs) throws SQLException, DataAccessException;
}

Should be updated to

@FunctionalInterface
public interface ResultSetExtractor<T extends @Nullable Object> {
    T extractData(ResultSet rs) throws SQLException, DataAccessException;
}

Unless I am mistaken, since ResultSetExtractor<T> is syntaxic sugar for ResultSetExtractor<T extends Object>, declaring ResultSetExtractor<T extends @Nullable Object> should not break the compatibility for users not using checkers like NullAway. If they do and they are using nullable type, the breakage is on purpose and will allow them to specify ResultSetExtractor<@Nullable T> on usage side.

Related Issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions