Message-ID: From: "tract-rob (@tract-rob)" To: "pgjdbc/pgjdbc" Date: Mon, 28 Oct 2024 23:27:39 +0000 Subject: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream List-Id: X-GitHub-Assignees: davecramer X-GitHub-Author-Id: 186636116 X-GitHub-Author-Login: tract-rob X-GitHub-Issue: 3426 X-GitHub-Labels: bug X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: closed X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3426 Content-Type: text/plain; charset=utf-8 Please read https://stackoverflow.com/help/minimal-reproducible-example **Describe the issue** Production code has been running error free since 2016, with the only change being regular driver upgrades. Upgrading from version 42.7.4 causes code to error...rolling back to 42.7.3 fixes the issue. The code is binding a java.io.FileInputStream via Anorm 2.5.3. Looking at Anorm source code it looks like it's bound using PreparedStatement.setBinaryStream. The exception returned when the statement is executed is: org.postgresql.util.PSQLException: Unable to bind parameter values for statement. at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:394) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:517) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:434) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:155) at com.zaxxer.hikari.proxy.PreparedStatementProxy.executeUpdate(PreparedStatementProxy.java:61) at com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.executeUpdate(PreparedStatementJavassistProxy.java) ... **Driver Version?** 42.7.4 **Java Version?** openjdk version "1.8.0_412" **OS Version?** Amazon Linux 2 **PostgreSQL Version?** 15.8 **To Reproduce** Steps to reproduce the behaviour: 1. Bind a java.io.FileInputStream object to e PreparedStatement using setBinaryStream. 2. call executeUpdate **Expected behaviour** A clear and concise description of what you expected to happen. And what actually happens For the last 8 years it's always successfully inserted the file into the database table. After driver upgrade, it just throws an error "Unable to bind parameter values for statement." **Logs** If possible PostgreSQL logs surrounding the occurrence of the issue Additionally logs from the driver can be obtained adding Using the following template code make sure the bug can be replicated in the driver alone. ``` import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Properties; public class TestNullsFirst { public static void main(String []args) throws Exception { String url = "jdbc:postgresql://localhost:5432/test"; Properties props = new Properties(); props.setProperty("user", "test"); props.setProperty("password", "test"); try ( Connection conn = DriverManager.getConnection(url, props) ){ try ( Statement statement = conn.createStatement() ) { try (ResultSet rs = statement.executeQuery( "select lastname from users order by lastname asc nulls first") ){ if (rs.next()) System.out.println( "Get String: " + rs.getString(1)); } } } } } ```