[CONJ-489] javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x Created: 2017-06-04  Updated: 2017-06-05  Resolved: 2017-06-05

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.5.9, 1.6.0, 2.0.1
Fix Version/s: 1.6.1, 2.0.2

Type: Bug Priority: Major
Reporter: Vorschuetz Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows



 Description   

Getting the following stack trace when trying to run XATransactions using Atomikos.

Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

Issue is caused by the XID to String conversion inside MariaXaResource.java

MariaXaResource.java

    static String xidToString(Xid xid) {
        StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
        sb.append("0x")
                .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                .append(",0x")
                .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                .append(",").append(xid.getFormatId());
        return sb.toString();
    }

hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

hexdump should be replaced by implementations like atomikos or mysql connector is using:

The following code would fix the issue:

Utils.java

....
    protected static String getHex(final byte[] raw) {
        final StringBuilder hex = new StringBuilder(2 * raw.length);
        for (final byte b : raw) {
            hex.append(hexArray[(b & 0xF0) >> 4])
                    .append(hexArray[(b & 0x0F)]);
        }
        return hex.toString();
    }
    
    public static String byteArrayToHexString(final byte[] bytes) {
        return (bytes != null) ? getHex(bytes) : "";
    }

MariaXaResource.java

...
    static String xidToString(Xid xid) {
        StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
        sb.append("0x")
                .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                .append(",0x")
                .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                .append(",").append(xid.getFormatId());
        return sb.toString();
    }
...



 Comments   
Comment by Diego Dupin [ 2017-06-05 ]

Thanks.
merge pull request

Generated at Thu Feb 08 03:16:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.