Skip to content
Permalink
Browse files

fix: NPE when calling setNull on a PreparedStatement with no paramete…

…rs (#1620)
  • Loading branch information
davecramer committed Nov 26, 2019
1 parent ff4a66d commit 6899a43dff735ab14a02bedea853266de768da50
@@ -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:
@@ -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.
You can’t perform that action at this time.