You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the issue PreparedStatement.setObject(1,null) throws NPE instead of SQLException when used on a query with no parameters (see code below)
Driver Version?
42.2.8
Java Version?
13
OS Version?
Mac (Irrelevant)
PostgreSQL Version?
12
To Reproduce
Steps to reproduce the behaviour:
importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.SQLException;
importjava.util.Map;
importjava.util.Properties;
importorg.postgresql.Driver;
publicclassNPE {
privatestaticfinalStringJDBC_URL = "jdbc:postgresql://<server>:5432/<database>";
privatestaticfinalStringUSERNAME = "postgres";
privatestaticfinalStringPASSWORD = "postgres";
@SuppressWarnings("resource")
publicstaticvoidmain(String[] args) throwsSQLException {
Propertiesproperties = newProperties();
properties.putAll(Map.of("user", USERNAME, "password", PASSWORD));
Connectionc = newDriver().connect(JDBC_URL, properties);
PreparedStatementps = c.prepareStatement("select 1"); // note there are no parameters// These throw NPE instead of SQLException// ps.setObject(-1, null);// ps.setObject( 0, null);ps.setObject( 1, null);
//// Exception in thread "main" java.lang.NullPointerException// at org.postgresql.core.v3.SimpleParameterList.setNull(SimpleParameterList.java:159)// at org.postgresql.jdbc.PgPreparedStatement.setNull(PgPreparedStatement.java:245)// at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:896)// at ...// This throws SQLE as expected// ps.setObject( 1, "");// // BTW: the error message is a bit wonky:// "The column index is out of range: 1, number of columns: 0."// but we are talking parameters rather than columns here.System.out.println("done.");
}
}
Expected behaviour
An SQLException should be thrown instead of an NPE
Logs
Shouldn't be needed – let me know if otherwise.
The text was updated successfully, but these errors were encountered:
There is no use case :)
I just noticed this while writing some tests and thought to report it because it might be that there is some other execution path (a "valid" one) that bypasses checks like this one.
I'm submitting a ...
Describe the issue
PreparedStatement.setObject(1,null)
throws NPE instead of SQLException when used on a query with no parameters (see code below)Driver Version?
42.2.8
Java Version?
13
OS Version?
Mac (Irrelevant)
PostgreSQL Version?
12
To Reproduce
Steps to reproduce the behaviour:
Expected behaviour
An SQLException should be thrown instead of an NPE
Logs
Shouldn't be needed – let me know if otherwise.
The text was updated successfully, but these errors were encountered: