Skip to content

Commit 5457f77

Browse files
committed
Fix usage before assignment
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 <[email protected]>
1 parent 0f45851 commit 5457f77

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ private void reset() {
512512
if (this.asyncDedicatedConnection != null) {
513513
try {
514514
if (customizedDatabaseIndex()) {
515-
potentiallySelectDatabase(this.defaultDbIndex);
515+
potentiallySelectDatabase(this.asyncDedicatedConnection, this.defaultDbIndex);
516516
}
517517
this.connectionProvider.release(this.asyncDedicatedConnection);
518518
this.asyncDedicatedConnection = null;
@@ -968,7 +968,7 @@ protected StatefulConnection<byte[], byte[]> doGetAsyncDedicatedConnection() {
968968
StatefulConnection<byte[], byte[]> connection = getConnectionProvider().getConnection(StatefulConnection.class);
969969

970970
if (customizedDatabaseIndex()) {
971-
potentiallySelectDatabase(this.dbIndex);
971+
potentiallySelectDatabase(connection, this.dbIndex);
972972
}
973973

974974
return connection;
@@ -1065,9 +1065,9 @@ private boolean customizedDatabaseIndex() {
10651065
return defaultDbIndex != dbIndex;
10661066
}
10671067

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

1070-
if (asyncDedicatedConnection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
1070+
if (connection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
10711071
statefulConnection.sync().select(dbIndex);
10721072
}
10731073
}

0 commit comments

Comments
 (0)