Skip to content

Commit

Permalink
fix: NPE when calling setNull on a PreparedStatement with no paramete…
Browse files Browse the repository at this point in the history
…rs (#1620)
  • Loading branch information
davecramer committed Nov 26, 2019
1 parent ff4a66d commit 6899a43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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
}
}
}

0 comments on commit 6899a43

Please sign in to comment.