pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: MrEasy (@MrEasy) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3365: EOFException on PreparedStatement#toString with unset bytea parameter since 42.7.4
Date: Thu, 29 Aug 2024 08:53:12 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

@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 {

```

view thread (34+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3365: EOFException on PreparedStatement#toString with unset bytea parameter since 42.7.4
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox