@@ -203,7 +203,7 @@ public <T, E extends Exception> T execute(
203203 if (this .writerConnection != null && !this .writerConnection .isClosed ()) {
204204 this .writerConnection .clearWarnings ();
205205 }
206- if (isConnectionUsable (this .readerConnection .get ())) {
206+ if (this . readerConnection != null && isConnectionUsable (this .readerConnection .get ())) {
207207 this .readerConnection .get ().clearWarnings ();
208208 }
209209 } catch (final SQLException e ) {
@@ -380,7 +380,7 @@ private void switchToWriterConnection(
380380 switchCurrentConnectionTo (this .writerConnection , writerHost );
381381 }
382382
383- if (this .isReaderConnFromInternalPool ) {
383+ if (this .isReaderConnFromInternalPool && this . readerConnection != null ) {
384384 this .closeConnectionIfIdle (this .readerConnection .get ());
385385 }
386386
@@ -412,13 +412,13 @@ private void switchToReaderConnection(final List<HostSpec> hosts)
412412 return ;
413413 }
414414
415- if (this .readerHostSpec != null && !hosts .contains (this .readerHostSpec )) {
415+ if (this .readerConnection != null && this . readerHostSpec != null && !hosts .contains (this .readerHostSpec )) {
416416 // The old reader cannot be used anymore because it is no longer in the list of allowed hosts.
417417 closeConnectionIfIdle (this .readerConnection .get ());
418418 }
419419
420420 this .inReadWriteSplit = true ;
421- if (!isConnectionUsable (this .readerConnection .get ())) {
421+ if (this . readerConnection == null || !isConnectionUsable (this .readerConnection .get ())) {
422422 initializeReaderConnection (hosts );
423423 } else {
424424 try {
@@ -572,6 +572,6 @@ Connection getWriterConnection() {
572572 }
573573
574574 Connection getReaderConnection () {
575- return this .readerConnection .get ();
575+ return this .readerConnection == null ? null : this . readerConnection .get ();
576576 }
577577}
0 commit comments