@@ -111,7 +111,7 @@ public static final Map<String, Object> defaultClientProperties() {
111111 private volatile boolean _running = false ;
112112
113113 /** Handler for (uncaught) exceptions that crop up in the {@link MainLoop}. */
114- private ExceptionHandler _exceptionHandler = new DefaultExceptionHandler () ;
114+ private ExceptionHandler _exceptionHandler ;
115115
116116 /** Object used for blocking main application thread when doing all the necessary
117117 * connection shutdown operations
@@ -207,15 +207,14 @@ public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
207207 this .password = params .getPassword ();
208208 this ._frameHandler = frameHandler ;
209209 this ._virtualHost = params .getVirtualHost ();
210- this ._exceptionHandler = params .getExceptionHandler ();
211210 this ._clientProperties = new HashMap <String , Object >(params .getClientProperties ());
212211 this .requestedFrameMax = params .getRequestedFrameMax ();
213212 this .requestedChannelMax = params .getRequestedChannelMax ();
214213 this .requestedHeartbeat = params .getRequestedHeartbeat ();
215214 this .saslConfig = params .getSaslConfig ();
216215
217216 this ._workService = new ConsumerWorkService (params .getExecutor ());
218- this ._exceptionHandler = params . getExceptionHandler ( );
217+ this ._exceptionHandler = initExceptionHandler ( params );
219218 this ._channelManager = null ;
220219
221220 this ._heartbeatSender = new HeartbeatSender (frameHandler );
@@ -224,7 +223,18 @@ public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
224223 this ._inConnectionNegotiation = true ; // we start out waiting for the first protocol response
225224 }
226225
227- /**
226+ private ExceptionHandler initExceptionHandler (ConnectionParams params ) {
227+ ExceptionHandler result = params .getExceptionHandler ();
228+ // null exception handler causes I/O thread to fail,
229+ // so be extra defensive here
230+ if (result == null ) {
231+ return new DefaultExceptionHandler ();
232+ } else {
233+ return result ;
234+ }
235+ }
236+
237+ /**
228238 * Start up the connection, including the MainLoop thread.
229239 * Sends the protocol
230240 * version negotiation header, and runs through
0 commit comments