@@ -203,7 +203,7 @@ public <T, E extends Exception> T execute(
203
203
if (this .writerConnection != null && !this .writerConnection .isClosed ()) {
204
204
this .writerConnection .clearWarnings ();
205
205
}
206
- if (isConnectionUsable (this .readerConnection .get ())) {
206
+ if (this . readerConnection != null && isConnectionUsable (this .readerConnection .get ())) {
207
207
this .readerConnection .get ().clearWarnings ();
208
208
}
209
209
} catch (final SQLException e ) {
@@ -380,7 +380,7 @@ private void switchToWriterConnection(
380
380
switchCurrentConnectionTo (this .writerConnection , writerHost );
381
381
}
382
382
383
- if (this .isReaderConnFromInternalPool ) {
383
+ if (this .isReaderConnFromInternalPool && this . readerConnection != null ) {
384
384
this .closeConnectionIfIdle (this .readerConnection .get ());
385
385
}
386
386
@@ -412,13 +412,13 @@ private void switchToReaderConnection(final List<HostSpec> hosts)
412
412
return ;
413
413
}
414
414
415
- if (this .readerHostSpec != null && !hosts .contains (this .readerHostSpec )) {
415
+ if (this .readerConnection != null && this . readerHostSpec != null && !hosts .contains (this .readerHostSpec )) {
416
416
// The old reader cannot be used anymore because it is no longer in the list of allowed hosts.
417
417
closeConnectionIfIdle (this .readerConnection .get ());
418
418
}
419
419
420
420
this .inReadWriteSplit = true ;
421
- if (!isConnectionUsable (this .readerConnection .get ())) {
421
+ if (this . readerConnection == null || !isConnectionUsable (this .readerConnection .get ())) {
422
422
initializeReaderConnection (hosts );
423
423
} else {
424
424
try {
@@ -572,6 +572,6 @@ Connection getWriterConnection() {
572
572
}
573
573
574
574
Connection getReaderConnection () {
575
- return this .readerConnection .get ();
575
+ return this .readerConnection == null ? null : this . readerConnection .get ();
576
576
}
577
577
}
0 commit comments