From ca9fbcea54564b95f4d1ed2f5ff2874082b36ca9 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Sun, 17 Oct 2021 23:43:46 +0200 Subject: [PATCH 1/2] More corrections for SocketInitiator/Acceptor tests - ensure connector is stopped when first assertion in `finally` block fails --- .../java/quickfix/SocketAcceptorTest.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/quickfixj-core/src/test/java/quickfix/SocketAcceptorTest.java b/quickfixj-core/src/test/java/quickfix/SocketAcceptorTest.java index 933b1d8103..747019ebce 100644 --- a/quickfixj-core/src/test/java/quickfix/SocketAcceptorTest.java +++ b/quickfixj-core/src/test/java/quickfix/SocketAcceptorTest.java @@ -102,22 +102,25 @@ public void testRestartOfAcceptor() throws Exception { assertTrue("acceptor should have logged on by now", acceptor.isLoggedOn()); assertTrue("initiator should have logged on by now", initiator.isLoggedOn()); } finally { - if (initiator != null) { - try { - initiator.stop(); - } catch (RuntimeException e) { - log.error(e.getMessage(), e); + try { + if (initiator != null) { + try { + initiator.stop(); + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + } } - } - testAcceptorApplication.waitForLogout(); - if (acceptor != null) { - try { - acceptor.stop(); - } catch (RuntimeException e) { - log.error(e.getMessage(), e); + testAcceptorApplication.waitForLogout(); + } finally { + if (acceptor != null) { + try { + acceptor.stop(); + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + } } + testInitiatorApplication.waitForLogout(); } - testInitiatorApplication.waitForLogout(); } } From 01f5ff0a1ca96571bc03f55ee23f11ce67117aa5 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Sun, 17 Oct 2021 23:47:41 +0200 Subject: [PATCH 2/2] Prevent NPE when `stop()` method is called prior to `start()` --- .../quickfix/mina/SingleThreadedEventHandlingStrategy.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java b/quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java index 58b7e1cf41..4d34d5ca97 100644 --- a/quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java +++ b/quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java @@ -194,7 +194,9 @@ public void stopHandlingMessages(boolean join) { stopHandlingMessages(); if (join) { try { - messageProcessingThread.join(); + if (messageProcessingThread != null) { + messageProcessingThread.join(); + } } catch (InterruptedException e) { sessionConnector.log.warn("{} interrupted.", MESSAGE_PROCESSOR_THREAD_NAME); Thread.currentThread().interrupt();