Bug #105706 NativePacketPayload.readInteger causes ArrayIndexOutOfBoundsException
Submitted: 25 Nov 2021 9:15 Modified: 3 Dec 2021 13:24
Reporter: Nicklas Wallgren Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.27 OS:Any
Assigned to: CPU Architecture:Any

[25 Nov 2021 9:15] Nicklas Wallgren
Description:
We have encountered ArrayIndexOutOfBoundsException in the NativePacketPayload.readInteger method. 

The exception occurs if the IntegerDataType is of type INT_LENENC and the bytebuffer is empty. 

Stacktrace
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.mysql.cj.protocol.a.NativePacketPayload.readInteger(NativePacketPayload.java:386) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativePacketPayload.readString(NativePacketPayload.java:593) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeServerSessionStateController$NativeServerSessionStateChanges.init(NativeServerSessionStateController.java:117) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.result.OkPacket.parse(OkPacket.java:64) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeProtocol.readServerStatusForResultSets(NativeProtocol.java:1691) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:116) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1600) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1654) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeProtocol.sendQueryPacket(NativeProtocol.java:1000) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.protocol.a.NativeProtocol.sendQueryString(NativeProtocol.java:933) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.NativeSession.execSQL(NativeSession.java:664) ~[mysql-connector-java-8.0.27.jar:8.0.27]
	at com.mysql.cj.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:2035) ~[mysql-connector-java-8.0.27.jar:8.0.27]

How to repeat:
I'm not sure of the cause, but I think it is related to one of our native queries.
Batch insert/update is activated in Hibernate.

INSERT INTO report_row_life_cycle_events(report_row_id, message, event_type, created_by, created_timestamp)
            SELECT
                rr.id,
                :message,
                :eventType,
                :username,
                NOW()
            FROM sender_productions sp
                JOIN transmission_broadcasts tb on tb.sender_production_id = sp.id
                JOIN report_rows rr ON tb.id = rr.transmission_broadcast_id
            WHERE
                sp.id = :senderProductionId
                AND rr.status < "33"
[29 Nov 2021 18:02] Filipe Silva
Hi Nicklas,

Thank you for your interest in MySQL.

What MySQL server version are you using? Also, are you setting `trackSessionState=true` in your connection configuration?
[3 Dec 2021 12:26] Nicklas Wallgren
Hey, thanks for the response.

You can probably close this issue since we're using the MySQL driver with a MariaDB server, which isn't supported I guess.

The problem went away after we changed to the MariaDB JDBC driver.
[3 Dec 2021 12:26] Nicklas Wallgren
Hey, thanks for the response.

You can probably close this issue since we're using the MySQL driver with a MariaDB server, which isn't supported I guess.

The problem went away after we changed to the MariaDB JDBC driver.
[3 Dec 2021 13:24] MySQL Verification Team
Thank you for the feedback.