Skip to content

Improve nullability annotations for PreparedStatement, CallableStatement, ResultSet#64

Merged
mernst merged 1 commit intotypetools:masterfrom
vlsi:resultset
Jul 26, 2020
Merged

Improve nullability annotations for PreparedStatement, CallableStatement, ResultSet#64
mernst merged 1 commit intotypetools:masterfrom
vlsi:resultset

Conversation

@vlsi
Copy link
Copy Markdown

@vlsi vlsi commented Jul 5, 2020

Most get... are allowed to return null (e.g. getString), so I added @Nullable for other getters like getRowid().

There are two less trivial changes:

a)

public <T> @Nullable T getObject(int parameterIndex, Class<T> type) throws SQLException;

I'm not sure if it should be written as public <@Nullable T> T ....

b) (...Calendar cal). It is not clear if the spec allows null calendar, however, AFAIK the implementations allow nulls, and there's an obscure Javadoc which suggests that calendar can be missing.
The only way I can imagine a "missing" calendar is a null reference.

    /**
     * Sets the designated parameter to the given <code>java.sql.Date</code> value,
     * using the given <code>Calendar</code> object.  The driver uses
     * the <code>Calendar</code> object to construct an SQL <code>DATE</code> value,
     * which the driver then sends to the database.  With
     * a <code>Calendar</code> object, the driver can calculate the date
     * taking into account a custom timezone.  If no
     * <code>Calendar</code> object is specified, the driver uses the default
     * timezone, which is that of the virtual machine running the application.
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x the parameter value
     * @param cal the <code>Calendar</code> object the driver will use
     *            to construct the date
     * @exception SQLException if parameterIndex does not correspond to a parameter
     * marker in the SQL statement; if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @since 1.2
     */
    void setDate(int parameterIndex, java.sql.@Nullable Date x, @Nullable Calendar cal)
            throws SQLException;

@mernst
Copy link
Copy Markdown
Member

mernst commented Jul 26, 2020

Thanks for these annotations!
I agree with your choice for (a) and your rationale for (b).

My apologies that this pull request languished. I wasn't watching the repository, so I didn't get notified.

@mernst mernst merged commit fb66e49 into typetools:master Jul 26, 2020
aosen-xiong pushed a commit to aosen-xiong/jdkopprop that referenced this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants