Copilot commented on code in PR #3654:
URL: https://github.com/apache/maven-surefire/pull/3654#discussion_r4733819640


##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnit4ListenersAdapter.java:
##########
@@ -19,185 +19,322 @@
 package org.apache.maven.surefire.junitplatform;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.TestExecutionResult.Status;
+import org.junit.platform.engine.TestSource;
 import org.junit.platform.engine.support.descriptor.ClassSource;
+import org.junit.platform.engine.support.descriptor.MethodSource;
 import org.junit.platform.launcher.TestExecutionListener;
 import org.junit.platform.launcher.TestIdentifier;
 import org.junit.platform.launcher.TestPlan;
+import org.opentest4j.MultipleFailuresError;
+import org.opentest4j.TestAbortedException;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
+import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
+import static org.junit.platform.engine.TestExecutionResult.Status.SUCCESSFUL;
+
+/**
+ * Calls JUnit 4 {@code RunListener}s the way JUnit 4 does: start and finish 
of each test, its failure,
+ * assumption failure or ignore. JUnit 4 is only on the test classpath, so it 
all goes through reflection.
+ */
 public class JUnit4ListenersAdapter implements TestExecutionListener {
 
+    private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
+
     private final List<Object> listeners;
 
+    // the loader the listeners come from, events can arrive on other threads
+    private final ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
+
+    // null before JUnit 4.12, no listener is thread safe then
+    private final Class<? extends Annotation> threadSafe = 
threadSafeAnnotation();
+
+    // like JUnit 4, listeners not marked thread safe are called one at a time
+    private final Object lock = new Object();
+
     public JUnit4ListenersAdapter(List<Object> runListener) {
         this.listeners = runListener;
     }
 
     @Override
     public void executionStarted(TestIdentifier testIdentifier) {
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-                    runListener
-                            .getClass()
-                            .getMethod("testRunStarted", descriptionClass)
-                            .invoke(runListener, (Object) null);
-                    runListener
-                            .getClass()
-                            .getMethod("testStarted", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        });
+        if (testIdentifier.isTest()) {
+            notifyListeners("testStarted", describe(testIdentifier));
+        }
     }
 
     @Override
     public void executionFinished(TestIdentifier testIdentifier, 
TestExecutionResult testExecutionResult) {
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-
-                    Class<?> resultClass =
-                            
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Result");
-
-                    runListener
-                            .getClass()
-                            .getMethod("testRunFinished", resultClass)
-                            .invoke(runListener, 
resultClass.getConstructor().newInstance());
-
-                    runListener
-                            .getClass()
-                            .getMethod("testFinished", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+        Status status = testExecutionResult.getStatus();
+        // like in JUnit 4, a class only shows up when it fails, for example 
in @BeforeClass
+        if (!testIdentifier.isTest() && status == SUCCESSFUL) {
+            return;
+        }
+        Object description = describe(testIdentifier);
+        List<Runnable> calls = new ArrayList<>();
+        if (status == FAILED) {
+            for (Throwable failure : failuresOf(testIdentifier, 
testExecutionResult)) {
+                calls.add(() -> notifyListeners("testFailure", 
newFailure(description, failure)));
             }
-        });
+        } else if (status == ABORTED) {
+            Throwable error = testExecutionResult
+                    .getThrowable()
+                    .orElseGet(() -> new TestAbortedException("Test aborted 
with no cause"));
+            calls.add(() -> notifyListeners("testAssumptionFailure", 
newFailure(description, error)));
+        }
+        if (testIdentifier.isTest()) {
+            calls.add(() -> notifyListeners("testFinished", description));
+        }
+        callAll(calls);
     }
 
     @Override
     public void executionSkipped(TestIdentifier testIdentifier, String reason) 
{
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-                    runListener
-                            .getClass()
-                            .getMethod("testIgnored", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        });
+        notifyListeners("testIgnored", describe(testIdentifier));
     }
 
     @Override
     public void testPlanExecutionStarted(TestPlan testPlan) {
+        Object suite = describeMainClass(testPlan);
+        if (suite != null) {
+            callAll(asList(
+                    () -> notifyListeners("testRunStarted", suite), () -> 
notifyListeners("testSuiteStarted", suite)));
+        }
+    }
+
+    @Override
+    public void testPlanExecutionFinished(TestPlan testPlan) {
+        Object suite = describeMainClass(testPlan);
+        if (suite != null) {
+            callAll(asList(
+                    () -> notifyListeners("testSuiteFinished", suite),
+                    () -> notifyListeners("testRunFinished", 
newInstance("org.junit.runner.Result", new Class<?>[0]))));
+        }
+    }
+
+    private static List<Throwable> failuresOf(TestIdentifier testIdentifier, 
TestExecutionResult result) {
+        // listeners call Failure.getMessage(), which needs an exception
+        Throwable error = result.getThrowable().orElseGet(() -> new 
AssertionError("Test failed with no cause"));
+        // Vintage wraps all failures of a test, say in its body and @After, 
in one error. JUnit 4 reports each.
+        // Only this exact class: AssertJ soft assertions subclass it and are 
one failure, like assertAll.
+        if (error.getClass() == MultipleFailuresError.class
+                && 
testIdentifier.getUniqueId().startsWith("[engine:junit-vintage]")
+                && madeByVintage((MultipleFailuresError) error)) {
+            return ((MultipleFailuresError) error).getFailures();
+        }
+        return singletonList(error);
+    }
+
+    // Vintage wraps two or more failures in an error of its own. Its stack is 
empty once the platform prunes it,
+    // or starts in Vintage with pruning off. One thrown by the test itself, 
like assertAll, stays one failure.
+    private static boolean madeByVintage(MultipleFailuresError error) {
+        StackTraceElement[] stack = error.getStackTrace();
+        return error.getFailures().size() > 1
+                && (stack.length == 0 || 
stack[0].getClassName().startsWith("org.junit.vintage."));

Review Comment:
   An empty stack does not establish that Vintage created this error. A JUnit 4 
test can throw its own `MultipleFailuresError` after calling `setStackTrace(new 
StackTraceElement[0])`; this predicate then splits that single failure into 
multiple `testFailure` callbacks, unlike the test-created-error behavior 
covered by the new tests. Please require additional wrapper-specific evidence 
before unwrapping a stackless error, and add a regression test for a 
test-created error with a cleared stack.



##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnit4ListenersAdapter.java:
##########
@@ -19,185 +19,322 @@
 package org.apache.maven.surefire.junitplatform;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.TestExecutionResult.Status;
+import org.junit.platform.engine.TestSource;
 import org.junit.platform.engine.support.descriptor.ClassSource;
+import org.junit.platform.engine.support.descriptor.MethodSource;
 import org.junit.platform.launcher.TestExecutionListener;
 import org.junit.platform.launcher.TestIdentifier;
 import org.junit.platform.launcher.TestPlan;
+import org.opentest4j.MultipleFailuresError;
+import org.opentest4j.TestAbortedException;
 
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
+import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
+import static org.junit.platform.engine.TestExecutionResult.Status.SUCCESSFUL;
+
+/**
+ * Calls JUnit 4 {@code RunListener}s the way JUnit 4 does: start and finish 
of each test, its failure,
+ * assumption failure or ignore. JUnit 4 is only on the test classpath, so it 
all goes through reflection.
+ */
 public class JUnit4ListenersAdapter implements TestExecutionListener {
 
+    private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
+
     private final List<Object> listeners;
 
+    // the loader the listeners come from, events can arrive on other threads
+    private final ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
+
+    // null before JUnit 4.12, no listener is thread safe then
+    private final Class<? extends Annotation> threadSafe = 
threadSafeAnnotation();
+
+    // like JUnit 4, listeners not marked thread safe are called one at a time
+    private final Object lock = new Object();
+
     public JUnit4ListenersAdapter(List<Object> runListener) {
         this.listeners = runListener;
     }
 
     @Override
     public void executionStarted(TestIdentifier testIdentifier) {
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-                    runListener
-                            .getClass()
-                            .getMethod("testRunStarted", descriptionClass)
-                            .invoke(runListener, (Object) null);
-                    runListener
-                            .getClass()
-                            .getMethod("testStarted", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        });
+        if (testIdentifier.isTest()) {
+            notifyListeners("testStarted", describe(testIdentifier));
+        }
     }
 
     @Override
     public void executionFinished(TestIdentifier testIdentifier, 
TestExecutionResult testExecutionResult) {
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-
-                    Class<?> resultClass =
-                            
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Result");
-
-                    runListener
-                            .getClass()
-                            .getMethod("testRunFinished", resultClass)
-                            .invoke(runListener, 
resultClass.getConstructor().newInstance());
-
-                    runListener
-                            .getClass()
-                            .getMethod("testFinished", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+        Status status = testExecutionResult.getStatus();
+        // like in JUnit 4, a class only shows up when it fails, for example 
in @BeforeClass
+        if (!testIdentifier.isTest() && status == SUCCESSFUL) {
+            return;
+        }
+        Object description = describe(testIdentifier);
+        List<Runnable> calls = new ArrayList<>();
+        if (status == FAILED) {
+            for (Throwable failure : failuresOf(testIdentifier, 
testExecutionResult)) {
+                calls.add(() -> notifyListeners("testFailure", 
newFailure(description, failure)));
             }
-        });
+        } else if (status == ABORTED) {
+            Throwable error = testExecutionResult
+                    .getThrowable()
+                    .orElseGet(() -> new TestAbortedException("Test aborted 
with no cause"));
+            calls.add(() -> notifyListeners("testAssumptionFailure", 
newFailure(description, error)));
+        }
+        if (testIdentifier.isTest()) {
+            calls.add(() -> notifyListeners("testFinished", description));
+        }
+        callAll(calls);
     }
 
     @Override
     public void executionSkipped(TestIdentifier testIdentifier, String reason) 
{
-        listeners.forEach(runListener -> {
-            try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createTestDescription = descriptionClass.getMethod(
-                        "createTestDescription", String.class, String.class, 
Annotation[].class);
-                if (testIdentifier.getSource().isPresent()
-                        && testIdentifier.getSource().get() instanceof 
ClassSource) {
-                    String className = ((ClassSource) 
testIdentifier.getSource().get()).getClassName();
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(className);
-                    Object invoke = createTestDescription.invoke(
-                            descriptionClass, classToRemove.getName(), 
testIdentifier.getDisplayName(), null);
-                    runListener
-                            .getClass()
-                            .getMethod("testIgnored", descriptionClass)
-                            .invoke(runListener, invoke);
-                }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        });
+        notifyListeners("testIgnored", describe(testIdentifier));
     }
 
     @Override
     public void testPlanExecutionStarted(TestPlan testPlan) {
+        Object suite = describeMainClass(testPlan);
+        if (suite != null) {
+            callAll(asList(
+                    () -> notifyListeners("testRunStarted", suite), () -> 
notifyListeners("testSuiteStarted", suite)));
+        }
+    }
+
+    @Override
+    public void testPlanExecutionFinished(TestPlan testPlan) {
+        Object suite = describeMainClass(testPlan);
+        if (suite != null) {
+            callAll(asList(
+                    () -> notifyListeners("testSuiteFinished", suite),
+                    () -> notifyListeners("testRunFinished", 
newInstance("org.junit.runner.Result", new Class<?>[0]))));
+        }
+    }
+
+    private static List<Throwable> failuresOf(TestIdentifier testIdentifier, 
TestExecutionResult result) {
+        // listeners call Failure.getMessage(), which needs an exception
+        Throwable error = result.getThrowable().orElseGet(() -> new 
AssertionError("Test failed with no cause"));
+        // Vintage wraps all failures of a test, say in its body and @After, 
in one error. JUnit 4 reports each.
+        // Only this exact class: AssertJ soft assertions subclass it and are 
one failure, like assertAll.
+        if (error.getClass() == MultipleFailuresError.class
+                && 
testIdentifier.getUniqueId().startsWith("[engine:junit-vintage]")
+                && madeByVintage((MultipleFailuresError) error)) {
+            return ((MultipleFailuresError) error).getFailures();
+        }
+        return singletonList(error);
+    }
+
+    // Vintage wraps two or more failures in an error of its own. Its stack is 
empty once the platform prunes it,
+    // or starts in Vintage with pruning off. One thrown by the test itself, 
like assertAll, stays one failure.
+    private static boolean madeByVintage(MultipleFailuresError error) {
+        StackTraceElement[] stack = error.getStackTrace();
+        return error.getFailures().size() > 1
+                && (stack.length == 0 || 
stack[0].getClassName().startsWith("org.junit.vintage."));
+    }
 
+    private Object describe(TestIdentifier testIdentifier) {
+        TestSource source = testIdentifier.getSource().orElse(null);
+        String name = testIdentifier.getLegacyReportingName();
+        if (source instanceof MethodSource) {
+            MethodSource method = (MethodSource) source;
+            return testDescription(method.getClassName(), name, 
annotationsOf(method));
+        }
+        if (source instanceof ClassSource) {
+            String className = ((ClassSource) source).getClassName();
+            // Vintage gives some tests a ClassSource, Parameterized ones for 
instance
+            return testIdentifier.isTest()
+                    ? testDescription(className, name, NO_ANNOTATIONS)
+                    : classDescription((ClassSource) source);
+        }
+        return suiteDescription(name);
+    }
+
+    private static Annotation[] annotationsOf(MethodSource source) {
+        try {
+            return source.getJavaMethod().getAnnotations();
+        } catch (RuntimeException e) {
+            // not always real code, a Spock feature name is not a Java method
+            return NO_ANNOTATIONS;
+        }
+    }
+
+    private Object describeMainClass(TestPlan testPlan) {
         String mainTestClass = extractMainClassName(testPlan);
-        listeners.forEach(runListener -> {
+        if (mainTestClass == null) {
+            return null;
+        }
+        try {
+            return createDescription("createSuiteDescription", new Class<?>[] 
{Class.class}, loadClass(mainTestClass));
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Object testDescription(String className, String name, Annotation[] 
annotations) {
+        return createDescription(
+                "createTestDescription",
+                new Class<?>[] {String.class, String.class, 
Annotation[].class},
+                className,
+                name,
+                annotations);
+    }
+
+    // like JUnit 4, a class description carries the class annotations, 
@Category for one
+    private Object classDescription(ClassSource source) {
+        try {
+            return createDescription("createSuiteDescription", new Class<?>[] 
{Class.class}, source.getJavaClass());
+        } catch (RuntimeException | LinkageError e) {
+            return suiteDescription(source.getClassName());
+        }
+    }
+
+    private Object suiteDescription(String name) {
+        return createDescription(
+                "createSuiteDescription", new Class<?>[] {String.class, 
Annotation[].class}, name, NO_ANNOTATIONS);
+    }
+
+    private Object createDescription(String factoryMethod, Class<?>[] 
parameterTypes, Object... arguments) {
+        try {
+            return loadClass("org.junit.runner.Description")
+                    .getMethod(factoryMethod, parameterTypes)
+                    .invoke(null, arguments);
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Object newFailure(Object description, Throwable error) {
+        return newInstance(
+                "org.junit.runner.notification.Failure",
+                new Class<?>[] {description.getClass(), Throwable.class},
+                description,
+                error);
+    }
+
+    private Object newInstance(String className, Class<?>[] parameterTypes, 
Object... arguments) {
+        try {
+            return 
loadClass(className).getConstructor(parameterTypes).newInstance(arguments);
+        } catch (ReflectiveOperationException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private void notifyListeners(String methodName, Object argument) {
+        notifyListeners(listeners, methodName, argument);
+    }
+
+    // like JUnit 4, a listener that throws doesn't stop the others, they get 
its exception as a failure.
+    // With no listener left to tell, it's thrown so the platform logs it.
+    private void notifyListeners(List<Object> targets, String methodName, 
Object argument) {
+        Method method;
+        try {
+            // the argument is a plain Description, Failure or Result, so its 
class is the parameter type
+            method = 
loadClass("org.junit.runner.notification.RunListener").getMethod(methodName, 
argument.getClass());
+        } catch (NoSuchMethodException e) {
+            // older JUnit 4, testSuiteStarted and testSuiteFinished only came 
with 4.13
+            return;
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+        List<Object> safeListeners = new ArrayList<>();
+        List<Throwable> errors = new ArrayList<>();
+        for (Object listener : targets) {
             try {
-                Class<?> descriptionClass =
-                        
Thread.currentThread().getContextClassLoader().loadClass("org.junit.runner.Description");
-                Method createSuiteDescription = 
descriptionClass.getMethod("createSuiteDescription", Class.class);
-                if (mainTestClass != null) {
-                    Class<?> classToRemove =
-                            
Thread.currentThread().getContextClassLoader().loadClass(mainTestClass);
-                    Object invoke = 
createSuiteDescription.invoke(descriptionClass, classToRemove);
-                    runListener
-                            .getClass()
-                            .getMethod("testRunStarted", descriptionClass)
-                            .invoke(runListener, invoke);
-                    runListener
-                            .getClass()
-                            .getMethod("testSuiteStarted", descriptionClass)
-                            .invoke(runListener, invoke);
+                call(listener, method, argument);
+                safeListeners.add(listener);
+            } catch (InvocationTargetException e) {
+                // JUnit 4 only catches exceptions, an Error still goes up
+                if (!(e.getCause() instanceof Exception)) {
+                    throw new RuntimeException(e);
                 }
-            } catch (NoSuchMethodException e) {
-                // ignore as the RunListener might not have implemented any of 
those methods
-            } catch (Exception e) {
+                errors.add(e.getCause());
+            } catch (IllegalAccessException e) {
                 throw new RuntimeException(e);
             }
-        });
+        }
+        if (!errors.isEmpty() && safeListeners.isEmpty()) {
+            RuntimeException thrown = new RuntimeException(errors.get(0));
+            errors.subList(1, errors.size()).forEach(thrown::addSuppressed);
+            throw thrown;
+        }
+        List<Runnable> failures = new ArrayList<>();
+        for (Throwable error : errors) {
+            failures.add(() -> notifyFailure(safeListeners, error));

Review Comment:
   If one listener throws and another inherits `RunListener`'s no-op 
`testFailure`, the exception is silently discarded after that callback returns. 
Surefire's separate reporting listener never receives this synthetic failure, 
and returning normally prevents the Platform from logging it. Log captured 
listener exceptions even when another listener accepts the notification.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to