Skip to content

Fix MySQLStatementCancelledException created with null SQLState#126

Open
gastaldi wants to merge 1 commit into
mysql:release/9.xfrom
gastaldi:fix/cancelled-exception-missing-sqlstate
Open

Fix MySQLStatementCancelledException created with null SQLState#126
gastaldi wants to merge 1 commit into
mysql:release/9.xfrom
gastaldi:fix/cancelled-exception-missing-sqlstate

Conversation

@gastaldi

@gastaldi gastaldi commented Jun 8, 2026

Copy link
Copy Markdown

Summary

  • SQLExceptionsMapping.translateException() used single-arg constructors for MySQLStatementCancelledException and MySQLTimeoutException, dropping the SQLState and vendorCode from the underlying CJException
  • OperationCancelledException inherited the generic "S1000" default from CJException instead of setting "70100" (SQLSTATE_MYSQL_QUERY_INTERRUPTED)

This caused MySQLStatementCancelledException.getSQLState() to return null, breaking frameworks like Spring JDBC that rely on SQLState for exception classification (producing UncategorizedSQLException instead of properly categorized exceptions).

Changes

  • OperationCancelledException: set default SQLState to MysqlErrorNumbers.SQLSTATE_MYSQL_QUERY_INTERRUPTED ("70100") in all constructors
  • SQLExceptionsMapping.translateException(): propagate SQLState and vendorCode when creating MySQLStatementCancelledException and MySQLTimeoutException

Test plan

  • Verify MySQLStatementCancelledException.getSQLState() returns "70100" after Statement.cancel() interrupts a running query
  • Verify MySQLTimeoutException.getSQLState() is not null after a query timeout

Fixes: #125

SQLExceptionsMapping.translateException() was using the single-arg
constructors for MySQLStatementCancelledException and MySQLTimeoutException,
which do not set the SQLState. This caused frameworks like Spring JDBC
that rely on getSQLState() for exception classification to produce
UncategorizedSQLException instead of properly categorized exceptions.

Also set the default SQLState in OperationCancelledException to "70100"
(SQLSTATE_MYSQL_QUERY_INTERRUPTED), matching MySQL's ER_QUERY_INTERRUPTED
error mapping.

Fixes: mysql#125
@mysql-oca-bot

Copy link
Copy Markdown

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQLStatementCancelledException has null SQLState

2 participants