{"record":{"id":"38a16eb9fd5ea80b","repo":"alibaba/druid","slug":"not-supported-by-highavailabledatasource","errorCode":null,"errorMessage":"Not supported by HighAvailableDataSource.","messagePattern":"Not supported by HighAvailableDataSource\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java","lineNumber":234,"sourceCode":"    public boolean isInBlackList(String name) {\n        return blacklist.contains(name);\n    }\n\n    public void setSelector(String name) {\n        DataSourceSelector selector = DataSourceSelectorFactory.getSelector(name, this);\n        if (selector != null) {\n            selector.init();\n            setDataSourceSelector(selector);\n        }\n    }\n\n    public String getSelector() {\n        return selector == null ? null : selector.getName();\n    }\n\n    @Override\n    public Connection getConnection(String username, String password) throws SQLException {\n        throw new UnsupportedOperationException(\"Not supported by HighAvailableDataSource.\");\n    }\n\n    @Override\n    public void setLoginTimeout(int seconds) {\n        DriverManager.setLoginTimeout(seconds);\n    }\n\n    @Override\n    public int getLoginTimeout() {\n        return DriverManager.getLoginTimeout();\n    }\n\n    public Logger getParentLogger() throws SQLFeatureNotSupportedException {\n        throw new SQLFeatureNotSupportedException();\n    }\n\n    public void setConnectionProperties(String connectionProperties) {\n        this.connectionProperties = connectionProperties;","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java#L216-L252","documentation":"HighAvailableDataSource.getConnection(String username, String password) is explicitly unimplemented — it always throws UnsupportedOperationException. The HA datasource routes through a selector that picks one of several underlying DruidDataSources and only supports the no-arg getConnection(), because per-call credential routing is not part of its design. Use the no-arg form with credentials configured on the underlying data sources.","triggerScenarios":"Calling highAvailableDataSource.getConnection(user, pass) directly, or wiring HighAvailableDataSource into a framework that invokes the two-argument getConnection (e.g. some connection providers, JdbcTemplate with explicit credentials, or user/password supplied in code).","commonSituations":"Migrating from a plain DruidDataSource (which accepts user/password per call) to HighAvailableDataSource without removing the per-call credentials; container-managed auth that resolves a subject and calls getConnection(user,pwd).","solutions":["Use the no-arg getConnection() and set username/password on each underlying DruidDataSource in the HA group.","If per-user connections are required, do not use HighAvailableDataSource — use a routing/abstract datasource that supports credential parameters, or obtain a specific underlying DataSource explicitly.","Configure the framework (e.g. Spring) to call getConnection() rather than getConnection(username, password)."],"exampleFix":"// before\nConnection c = haDataSource.getConnection(\"alice\", \"secret\"); // throws\n\n// after\n// configure credentials on each underlying source once:\n//   ds1.setUsername(\"alice\"); ds1.setPassword(\"secret\");\nConnection c = haDataSource.getConnection();","handlingStrategy":"validation","validationCode":"// Do not call the two-arg form on HA data sources:\nif (ds instanceof HighAvailableDataSource) {\n    throw new IllegalArgumentException(\"use getConnection() and set credentials on the underlying sources\");\n}","typeGuard":"public static boolean supportsCredentialedGetConnection(DataSource ds) {\n    return !(ds instanceof HighAvailableDataSource);\n}","tryCatchPattern":"try {\n    conn = ds.getConnection(user, pass);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"HighAvailableDataSource\")) {\n        conn = ds.getConnection(); // credentials already on underlying sources\n    } else throw e;\n}","preventionTips":["Set credentials on each underlying DruidDataSource in the HA group, not per-call.","Wire frameworks to call the no-arg getConnection().","Use a different DataSource type if per-user credentials are truly required."],"tags":["ha-datasource","unsupported-operation","authentication","jdbc"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}