When cancelling an other query from an other thread, you might get an NPE in rare cases:
As you see, 'protocol' is null in https://github.com/mariadb-corporation/mariadb-connector-j/blob/2.7.5/src/main/java/org/mariadb/jdbc/MariaDbStatement.java#L1187
I investigate a bit and have the following explanation for the bug:
Thread #1 starts a query
Thread #2 tries to cancel the query.
It invokes L980 protocol.cancelCurrentQuery() successfully
Thread #1 now closes the query and sets protocol = null
When Thread #2 tries to execute L981, which calls L1187 protocol.skip() - you get an NPE.
There is no kind of locking the access of protocol and this can be modified in a concurrent thread.
Unfortunately, I cannot provide a test. The bug is very hard to reproduce and happens only in production...
Side note: I think the bug may not happen with 3.x, because the code is totally different (but we did not update to 3.x, yet)