{"record":{"id":"5da38285cf119516","repo":"apache/shardingsphere","slug":"5-5da382","errorCode":"5","errorMessage":"Underlying SQL state: %s, underlying error code: %s.","messagePattern":"Underlying SQL state: (.+?), underlying error code: (.+?)\\.","errorType":"exception","errorClass":"SQLWrapperException","httpStatus":null,"severity":"warning","filePath":"infra/util/src/main/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloser.java","lineNumber":63,"sourceCode":"                    ((AutoCloseable) each).close();\n                    // CHECKSTYLE:OFF\n                } catch (final Exception ex) {\n                    // CHECKSTYLE:ON\n                    causes.add(ex);\n                }\n            }\n        }\n        if (!causes.isEmpty()) {\n            throwException(causes);\n        }\n    }\n    \n    private static void throwException(final Collection<Exception> causes) {\n        SQLException sqlException = new SQLException(\"\");\n        for (Exception each : causes) {\n            sqlException.setNextException(new SQLException(each));\n        }\n        throw new SQLWrapperException(sqlException);\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/infra/util/src/main/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloser.java#L45-L66","documentation":"Thrown as SQLWrapperException when closing a group of DataSources and one or more close() calls fail with SQLException. The wrapper chains every underlying failure via SQLException.setNextException, and its message template reports the underlying SQL state and error code so callers can see which driver/database actually failed. It is a shutdown-time aggregation error: the original causes are preserved in the chain, not swallowed.","triggerScenarios":"Calling DataSourcesCloser.close (or any path that closes multiple pooled DataSources, e.g. datasource teardown on application shutdown) where at least one underlying JDBC DataSource.close() throws a SQLException; the collected causes are wrapped and rethrown.","commonSituations":"Application shutdown while connections are still in flight; connection pools (HikariCP/DBCP) already invalidated or their DB unreachable at close time; closing a datasource that failed mid-initialization; double-closing datasources in a context-destroy callback.","solutions":["Inspect the wrapped exception chain via getNextException() on the SQLWrapperException to find the real SQLState/vendor code of the failing datasource.","Ensure connections/statements are closed by application code before container shutdown invokes datasource close.","If the error is transient (DB restarted), verify the database is reachable and retry the shutdown/close sequence.","If a specific datasource is misconfigured (wrong URL, expired credentials), fix its configuration so close() no longer fails."],"exampleFix":"// before\ncatch (final SQLException ex) {\n    throw new SQLWrapperException(sqlException);\n}\n// caller: inspect chain\n// after\ncatch (final SQLWrapperException ex) {\n    SQLException next = ex.getNextException();\n    while (next != null) {\n        LOG.error(\"close failed: state={}, code={}\", next.getSQLState(), next.getErrorCode(), next);\n        next = next.getNextException();\n    }\n}","handlingStrategy":"try-catch","validationCode":"// before teardown: verify pools are idle\nfor (DataSource ds : pools) { /* drain/quiet app queries first */ }","typeGuard":null,"tryCatchPattern":"catch (final SQLWrapperException ex) { for (SQLException n = ex.getNextException(); n != null; n = n.getNextException()) { log(\"state={} code={}\", n.getSQLState(), n.getErrorCode()); } }","preventionTips":["Close all application connections before datasource close","Never close datasources twice","Log the full exception chain to identify the failing pool"],"tags":["jdbc","connection-pool","shutdown","sql-state"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}