Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1346

Log-And-Throw Antipattern in ClientMessage

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 3.5.10
    • 3.5.11
    • Other
    • None
    • any

    Description

      The mariadb JDBC driver will log warning messages when errors happen, and then throws an exception.

      This is known as the log-then-throw antipattern.

      In our case, we're handling those exceptions, and the logged warning is irritating for users (see https://github.com/keycloak/keycloak/issues/51920)

      Suggested fix: When throws an exception, never log.

      Problematic code: Whenever "new ErrorPacket(buf, context);" is called, it will log the error. This is not what we need/want when an exception is thrown directly after.

      https://github.com/mariadb-corporation/mariadb-connector-j/blob/6164678e83aa9d203939d5bec73bd4571cbec8a2/src/main/java/org/mariadb/jdbc/message/ClientMessage.java#L191-L197

      Possible fixes:

      • Remove the warning
      • Downgrade the log to DEBUG/TRACE
      • Pass a parameter to the constructor when it should not be logged as a warning

      Once we agree on the solution, I'm happy to contribute a PR.

      Other places like PreparePacket.java:74, PrepareExecutePacket.java:158, StandardClient.java:342/510, and Result.java:220/282 are affected as well.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            ahus1 Alexander Schwartz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.