The following Connector-J test case reproduces the problem. It only happens if writeq_high_water is lower than max_allowed_packet on the server. Due to the recent changes to the default values, this is unlikely to happen in older versions if the default values are used.
A workaround to this is to use the old default value for writeq_high_water. It won't eliminate the problem but it helps reduce the likelihood of it happening. Disabling the writeq throttling completely will prevent it but that can cause extreme memory usage.