Skip to content

Commit

Permalink
Fix usage before assignment
Browse files Browse the repository at this point in the history
When new connection is created in doGetAsyncDedicatedConnection(), it is
not yet assigned to asyncDedicatedConnection attribute, so it cannot be
used in potentiallySelectDatabase() call. Fix this by passing the
connection to the method.

Closes spring-projects#2984

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
  • Loading branch information
oldium committed Sep 8, 2024
1 parent 0f45851 commit 5457f77
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ private void reset() {
if (this.asyncDedicatedConnection != null) {
try {
if (customizedDatabaseIndex()) {
potentiallySelectDatabase(this.defaultDbIndex);
potentiallySelectDatabase(this.asyncDedicatedConnection, this.defaultDbIndex);
}
this.connectionProvider.release(this.asyncDedicatedConnection);
this.asyncDedicatedConnection = null;
Expand Down Expand Up @@ -968,7 +968,7 @@ protected StatefulConnection<byte[], byte[]> doGetAsyncDedicatedConnection() {
StatefulConnection<byte[], byte[]> connection = getConnectionProvider().getConnection(StatefulConnection.class);

if (customizedDatabaseIndex()) {
potentiallySelectDatabase(this.dbIndex);
potentiallySelectDatabase(connection, this.dbIndex);
}

return connection;
Expand Down Expand Up @@ -1065,9 +1065,9 @@ private boolean customizedDatabaseIndex() {
return defaultDbIndex != dbIndex;
}

private void potentiallySelectDatabase(int dbIndex) {
private void potentiallySelectDatabase(StatefulConnection<byte[], byte[]> connection, int dbIndex) {

if (asyncDedicatedConnection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
if (connection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
statefulConnection.sync().select(dbIndex);
}
}
Expand Down

0 comments on commit 5457f77

Please sign in to comment.