{"record":{"id":"9396c66baffbe587","repo":"quarkusio/quarkus","slug":"data-error-9396c6","errorCode":"DATA_ERROR","errorMessage":"Failed to re-encode xml data.","messagePattern":"Failed to re-encode xml data\\.","errorType":"error_code","errorClass":"PSQLException","httpStatus":null,"severity":"error","filePath":"extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/PgSQLXML.java","lineNumber":136,"sourceCode":"\n    @Substitute\n    @Override\n    public synchronized InputStream getBinaryStream() throws SQLException {\n        checkFreed();\n        ensureInitialized();\n\n        if (data == null) {\n            return null;\n        }\n\n        try {\n            return new ByteArrayInputStream(conn.getEncoding().encode(data));\n        } catch (IOException ioe) {\n            // This should be a can't happen exception. We just\n            // decoded this data, so it would be surprising that\n            // we couldn't encode it.\n            // For this reason don't make it translatable.\n            throw new PSQLException(\"Failed to re-encode xml data.\", PSQLState.DATA_ERROR, ioe);\n        }\n    }\n\n    @Substitute\n    @Override\n    public synchronized Reader getCharacterStream() throws SQLException {\n        checkFreed();\n        ensureInitialized();\n\n        if (data == null) {\n            return null;\n        }\n\n        return new StringReader(data);\n    }\n\n    // We must implement this unsafely because that's what the\n    // interface requires. Because it says we're returning T","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/PgSQLXML.java#L118-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"Non-UTF8 client_encoding values; characters in the XML not representable in the connection charset; native-image-specific encoding issues.","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."],"exampleFix":"// before\njdbc:postgresql://host/db?options=-c%20client_encoding%3DLATIN1\n// after\njdbc:postgresql://host/db?options=-c%20client_encoding%3DUTF8","handlingStrategy":"try-catch","validationCode":"boolean utf8Ok = \"UTF-8\".equalsIgnoreCase(connEncoding);\n// ensure client_encoding=UTF8 before using SQLXML binary streams","typeGuard":null,"tryCatchPattern":"try (InputStream is = sqlxml.getBinaryStream()) {\n    // consume xml bytes\n} catch (PSQLException e) {\n    if (e.getMessage().contains(\"Failed to re-encode xml data.\")) {\n        log.error(\"Re-encode failed; use UTF-8 client_encoding or getString()\", e);\n        String xml = sqlxml.getString(); // fallback\n    } else { throw e; }\n}","preventionTips":["Force client_encoding=UTF8 on the connection","Prefer getCharacterStream()/getString() for SQLXML access","Keep the quarkus-jdbc-postgresql extension up to date"],"tags":["postgresql","sqlxml","encoding","native-image"],"backgroundTag":"xml-encoding-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}