Skip to content

How specify nullable primitive array generic result type? #1494

@msqr

Description

@msqr

I'm using NullAway 0.13.1 in Java 27 with Spring 7, which has this API:

public interface PreparedStatementCallback<T extends @Nullable Object> {

	T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;

}

I have an implementation that can return a nullable byte[] result:

private static final PreparedStatementCallback<byte @Nullable []> DATA_CALLBACK = new PreparedStatementCallback<>() {

	@Override
	public byte @Nullable [] doInPreparedStatement(PreparedStatement ps)
			throws SQLException, DataAccessException {
		if ( ps.execute() ) {
			try (ResultSet rs = ps.getResultSet()) {
				if ( rs.next() ) {
					return rs.getBytes(1);
				}
			}
		}
		return null;
	}
};

NullAway reports this as an error:

error: [NullAway] method returns @Nullable, but superclass method org.springframework.jdbc.core.PreparedStatementCallback.doInPreparedStatement(java.sql.PreparedStatement) returns @NonNull
                public byte @Nullable [] doInPreparedStatement(PreparedStatement ps)
                                         ^
      (see http://t.uber.com/nullaway )
  1 error

I do not get this type of error using a nullable Object result like PreparedStatementCallback<@Nullable String>. Am I writing the byte @Nullable [] version incorrectly somehow? I feel like it should not generate this error, but am not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions