pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: rlbdv (@rlbdv) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7
Date: Sun, 10 Aug 2025 23:11:11 +0000
Message-ID: <[email protected]> (raw)

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)


view thread (17+ 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 #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7
  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