From 690b5a2020157c8da66fd9ed9ba0a971452de195 Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 5 Oct 2026 06:33:49 +0200 Subject: [PATCH 1/3] filtering exceptions from NioDatagramAcceptor --- .../socket/nio/NioDatagramAcceptorTest.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java index cca9be7ca..402fa564c 100644 --- a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java +++ b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java @@ -41,7 +41,9 @@ public void shouldDisposeAcceptorSilentlyWhenExecutorIsShutdown() { ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { - exception.set(cause); + if (isFromNioDatagramAcceptor(cause)) { + exception.set(cause); + } } }); @@ -72,7 +74,9 @@ public void shouldThrowExceptionWhenThreadIsInterruptedAndServiceIsNotDisposing( ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { - exception.set(cause); + if (isFromNioDatagramAcceptor(cause)) { + exception.set(cause); + } } }); @@ -106,4 +110,14 @@ public void exceptionCaught(Throwable cause) { ExceptionMonitor.setInstance(null); } } + + private static boolean isFromNioDatagramAcceptor(Throwable cause) { + for (StackTraceElement stackTraceElement : cause.getStackTrace()) { + String className = stackTraceElement.getClassName(); + if (className.equals(NioDatagramAcceptor.class.getName())) { + return true; + } + } + return false; + } } From 5bb8e0f660e2c4831e70a86783ff57f76f0e2a65 Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 10 Oct 2026 09:31:37 +0200 Subject: [PATCH 2/3] Additional logging added --- .../socket/nio/NioDatagramAcceptorTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java index 402fa564c..89d0addbc 100644 --- a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java +++ b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java @@ -24,6 +24,8 @@ import org.apache.mina.util.AcceptorBindUtil; import org.apache.mina.util.ExceptionMonitor; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -34,13 +36,18 @@ public class NioDatagramAcceptorTest { + private static final Logger LOGGER = LoggerFactory.getLogger(NioDatagramAcceptorTest.class); + @Test public void shouldDisposeAcceptorSilentlyWhenExecutorIsShutdown() { AtomicReference exception = new AtomicReference<>(); + ExceptionMonitor previous = ExceptionMonitor.getInstance(); ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { + LOGGER.error("Exception caught", cause); + if (isFromNioDatagramAcceptor(cause)) { exception.set(cause); } @@ -63,7 +70,7 @@ public void exceptionCaught(Throwable cause) { assertNull("Exception must not be thrown when disposing executor service", exception.get()); } } finally { - ExceptionMonitor.setInstance(null); + ExceptionMonitor.setInstance(previous); } } @@ -71,9 +78,12 @@ public void exceptionCaught(Throwable cause) { public void shouldThrowExceptionWhenThreadIsInterruptedAndServiceIsNotDisposing() { AtomicReference exception = new AtomicReference<>(); + ExceptionMonitor previous = ExceptionMonitor.getInstance(); ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { + LOGGER.error("Exception caught", cause); + if (isFromNioDatagramAcceptor(cause)) { exception.set(cause); } @@ -107,7 +117,7 @@ public void exceptionCaught(Throwable cause) { } } } finally { - ExceptionMonitor.setInstance(null); + ExceptionMonitor.setInstance(previous); } } From 1ad92cf5bbcffb6b083a80f9a88671084d12ff3e Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 10 Oct 2026 10:22:06 +0200 Subject: [PATCH 3/3] Print test names for caught exceptions. --- .../transport/socket/nio/NioDatagramAcceptorTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java index 89d0addbc..07d40e482 100644 --- a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java +++ b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java @@ -23,7 +23,9 @@ import org.apache.mina.transport.socket.DatagramSessionConfig; import org.apache.mina.util.AcceptorBindUtil; import org.apache.mina.util.ExceptionMonitor; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,9 @@ public class NioDatagramAcceptorTest { private static final Logger LOGGER = LoggerFactory.getLogger(NioDatagramAcceptorTest.class); + @Rule + public TestName testName = new TestName(); + @Test public void shouldDisposeAcceptorSilentlyWhenExecutorIsShutdown() { AtomicReference exception = new AtomicReference<>(); @@ -46,7 +51,7 @@ public void shouldDisposeAcceptorSilentlyWhenExecutorIsShutdown() { ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { - LOGGER.error("Exception caught", cause); + LOGGER.error("Exception caught in test {}", testName.getMethodName(), cause); if (isFromNioDatagramAcceptor(cause)) { exception.set(cause); @@ -82,7 +87,7 @@ public void shouldThrowExceptionWhenThreadIsInterruptedAndServiceIsNotDisposing( ExceptionMonitor.setInstance(new ExceptionMonitor() { @Override public void exceptionCaught(Throwable cause) { - LOGGER.error("Exception caught", cause); + LOGGER.error("Exception caught in test {}", testName.getMethodName(), cause); if (isFromNioDatagramAcceptor(cause)) { exception.set(cause);