quarkusio/quarkus · error · PSQLException
DATA_ERROR
DATA_ERROR
Error message
Failed to re-encode xml data.
What it means
PgSQLXML.getBinaryStream() re-encodes an in-memory XML string to bytes using the connection's encoding. An IOException here should be impossible (the data was just decoded), so the code throws a PSQLException with SQLState DATA_ERROR and the message 'Failed to re-encode xml data.'. This is a GraalVM substitution of the PostgreSQL driver's PgSQLXML class.
Source
Thrown at extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/PgSQLXML.java:136
@Substitute
@Override
public synchronized InputStream getBinaryStream() throws SQLException {
checkFreed();
ensureInitialized();
if (data == null) {
return null;
}
try {
return new ByteArrayInputStream(conn.getEncoding().encode(data));
} catch (IOException ioe) {
// This should be a can't happen exception. We just
// decoded this data, so it would be surprising that
// we couldn't encode it.
// For this reason don't make it translatable.
throw new PSQLException("Failed to re-encode xml data.", PSQLState.DATA_ERROR, ioe);
}
}
@Substitute
@Override
public synchronized Reader getCharacterStream() throws SQLException {
checkFreed();
ensureInitialized();
if (data == null) {
return null;
}
return new StringReader(data);
}
// We must implement this unsafely because that's what the
// interface requires. Because it says we're returning TView on GitHub (pinned to e1c734241f)
Solutions
- Use a UTF-8 connection encoding (client_encoding=UTF8) so re-encoding cannot fail.
- Inspect the chained IOException cause to identify the encoding problem.
- Prefer getCharacterStream()/getString() over getBinaryStream() when handling XML data.
- Update the quarkus-jdbc-postgresql extension to pick up fixed PgSQLXML substitutions.
Example fix
// before jdbc:postgresql://host/db?options=-c%20client_encoding%3DLATIN1 // after jdbc:postgresql://host/db?options=-c%20client_encoding%3DUTF8
Defensive patterns
Strategy: try-catch
Validate before calling
boolean utf8Ok = "UTF-8".equalsIgnoreCase(connEncoding); // ensure client_encoding=UTF8 before using SQLXML binary streams
Try / catch
try (InputStream is = sqlxml.getBinaryStream()) {
// consume xml bytes
} catch (PSQLException e) {
if (e.getMessage().contains("Failed to re-encode xml data.")) {
log.error("Re-encode failed; use UTF-8 client_encoding or getString()", e);
String xml = sqlxml.getString(); // fallback
} else { throw e; }
} Prevention
- Force client_encoding=UTF8 on the connection
- Prefer getCharacterStream()/getString() for SQLXML access
- Keep the quarkus-jdbc-postgresql extension up to date
When it happens
Trigger: Calling getBinaryStream() on a SQLXML object whose charset encoding back to bytes fails — e.g. the connection encoding cannot represent the decoded data, or the encoding lookup throws in native mode.
Common situations: Non-UTF8 client_encoding values; characters in the XML not representable in the connection charset; native-image-specific encoding issues.
Related errors
- DATA_ERROR
- INVALID_PARAMETER_TYPE
- The org.postgresql.sspi.SSPIClient is not available on Graal
- UNEXPECTED_ERROR
- OBJECT_NOT_IN_STATE
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/9396c66baffbe587.
Report an issue: GitHub.