Message-ID: From: "rlbdv (@rlbdv)" To: "pgjdbc/pgjdbc" Date: Sun, 10 Aug 2025 23:11:11 +0000 Subject: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7 List-Id: X-GitHub-Author-Id: 2295838 X-GitHub-Author-Login: rlbdv X-GitHub-Issue: 3757 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3757 Content-Type: text/plain; charset=utf-8 With 42.7.7 this code fails: ``` // assuming: create table test (data bytea) s = connection.prepareStatement("insert into test (data) values (?)"); obj = PGobject(); obj.setType("bytea"); obj.setValue("\\x01020304"); s.setObject(1, obj); s.toString() ``` with: ``` org.postgresql.util.PSQLException: Unable to convert bytea parameter at position 0 to literal at org.postgresql.core.v3.SimpleParameterList.toString (SimpleParameterList.java:267) org.postgresql.core.NativeQuery.toString (NativeQuery.java:73) org.postgresql.core.v3.SimpleQuery.toString (SimpleQuery.java:63) org.postgresql.core.v3.SimpleQuery.toString (SimpleQuery.java:58) org.postgresql.jdbc.PgPreparedStatement.toString (PgPreparedStatement.java:1107) ... ``` Possibly related: #3365 This problem was discovered after one of PuppetDB's concurrency tests failed. The test was deliberately provoking an expected database transaction serialization exception, and when that exception occurred, it provoked a crash in `PGbytea.toPGLiteral` because it was passed the `PGObject`'s "\x..." `getValue` string and `toPGLiteral` has no handler for `String` (only `byte[]`). As a result, it throws the final "Can't convert String to bytea" `IllegalArgumentException`. The test ends up in `toPGLiteral` via `BatchResultHandler.handleError()`'s attempt to produce a string via `queries[resultIndex].toString(...)`. I'm not certain, but I'm moderately sure that the `SimpleParameterList.toString` failure is caused by the same final throw in `toPGLiteral`. ## Environment: Debian/trixie PostgreSQL Debian 17.5-1 openjdk version "21.0.8" 2025-07-15 OpenJDK Runtime Environment (build 21.0.8+9-Debian-1) OpenJDK 64-Bit Server VM (build 21.0.8+9-Debian-1, mixed mode, sharing)