Message-ID: From: "MrEasy (@MrEasy)" To: "pgjdbc/pgjdbc" Date: Thu, 29 Aug 2024 08:53:12 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3365: EOFException on PreparedStatement#toString with unset bytea parameter since 42.7.4 In-Reply-To: References: List-Id: X-GitHub-Author-Login: MrEasy X-GitHub-Comment-Id: 2317062533 X-GitHub-Comment-Type: issue_comment X-GitHub-Edited-At: 2024-08-29T08:53:55Z X-GitHub-Issue: 3365 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3365#issuecomment-2317062533 Content-Type: text/plain; charset=utf-8 @davecramer you are right, a simple prepare + toString does not reproduce it. It actually has to get invoced twice and also probably the values assigned. The following added test case reproduces the issue: ``` diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java --- a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java (revision e33be5c0481c22f4242a5d7ef2d2c09c8a17179f) +++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java (date 1724921450096) @@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -236,6 +237,28 @@ pstmt.executeUpdate(); pstmt.close(); } + + @Test + public void testToStringOnPreparedStatement() throws SQLException { + PreparedStatement pstmt = + con.prepareStatement("INSERT INTO streamtable VALUES (?,?)"); + + byte[] buf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ByteArrayInputStream byteStream = new ByteArrayInputStream(buf); + + pstmt.setBinaryStream(1, byteStream, buf.length); + pstmt.setString(2, "test"); + + String pstmtString = pstmt.toString(); + assertNotNull(pstmtString); + + // 2nd invoke of #tostring reproduces #3365 + // throws exception: org.postgresql.util.PSQLException: Unable to convert bytea parameter at position 0 to literal + pstmtString = pstmt.toString(); + assertNotNull(pstmtString); + + pstmt.close(); + } @Test public void testTrailingSpaces() throws SQLException { ```