Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NPE when calling setNull on a PreparedStatement with no parameters #1620

Merged
merged 1 commit into from Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -183,6 +183,13 @@ public void closeImpl() throws SQLException {
public void setNull(int parameterIndex, int sqlType) throws SQLException {
checkClosed();

if (parameterIndex < 1 || parameterIndex > preparedParameters.getInParameterCount()) {
throw new PSQLException(
GT.tr("The column index is out of range: {0}, number of columns: {1}.",
parameterIndex, preparedParameters.getInParameterCount()),
PSQLState.INVALID_PARAMETER_VALUE);
}

int oid;
switch (sqlType) {
case Types.SQLXML:
Expand Down
Expand Up @@ -1516,4 +1516,16 @@ public void close() throws SecurityException {
log.setLevel(prevLevel);
}
}

@Test
public void testNoParametersNPE() throws SQLException {
try {
PreparedStatement ps = con.prepareStatement("select 1");
ps.setString(1, "null");
} catch ( NullPointerException ex ) {
fail("Should throw a SQLException");
} catch (SQLException ex) {
// ignore
}
}
}