@@ -77,17 +77,21 @@ public static Object intercept(@This final Object callable, @SuperCall final Cal
7777
7878 Object result = null ;
7979 Throwable thrown = null ;
80- for (MethodWatcher watcher : methodWatcherLoader ) {
81- watcher .beforeInvocation (target , method , params );
80+ synchronized (methodWatcherLoader ) {
81+ for (MethodWatcher watcher : methodWatcherLoader ) {
82+ watcher .beforeInvocation (target , method , params );
83+ }
8284 }
8385
8486 try {
8587 result = LifecycleHooks .callProxy (proxy );
8688 } catch (Throwable t ) {
8789 thrown = t ;
8890 } finally {
89- for (MethodWatcher watcher : methodWatcherLoader ) {
90- watcher .afterInvocation (target , method , thrown );
91+ synchronized (methodWatcherLoader ) {
92+ for (MethodWatcher watcher : methodWatcherLoader ) {
93+ watcher .afterInvocation (target , method , thrown );
94+ }
9195 }
9296 }
9397
@@ -108,8 +112,10 @@ public static Object intercept(@This final Object callable, @SuperCall final Cal
108112 static void fireTestStarted (TestClass testClass , Runnable runnable ) {
109113 AtomicTest atomicTest = createAtomicTest (testClass , runnable );
110114 if (atomicTest != null ) {
111- for (RunWatcher watcher : runWatcherLoader ) {
112- watcher .testStarted (atomicTest .getIdentity (), atomicTest .getTestClass ());
115+ synchronized (runWatcherLoader ) {
116+ for (RunWatcher watcher : runWatcherLoader ) {
117+ watcher .testStarted (atomicTest .getIdentity (), atomicTest .getTestClass ());
118+ }
113119 }
114120 }
115121 }
@@ -122,9 +128,11 @@ static void fireTestStarted(TestClass testClass, Runnable runnable) {
122128 static void fireTestFinished (TestClass testClass ) {
123129 AtomicTest atomicTest = TESTCLASS_TO_ATOMICTEST .get (testClass );
124130 if (atomicTest != null ) {
125- for (RunWatcher watcher : runWatcherLoader ) {
126- notifyIfTestFailed (watcher , atomicTest );
127- watcher .testFinished (atomicTest .getIdentity (), atomicTest .getTestClass ());
131+ synchronized (runWatcherLoader ) {
132+ for (RunWatcher watcher : runWatcherLoader ) {
133+ notifyIfTestFailed (watcher , atomicTest );
134+ watcher .testFinished (atomicTest .getIdentity (), atomicTest .getTestClass ());
135+ }
128136 }
129137 }
130138 }
@@ -155,8 +163,10 @@ private static void notifyIfTestFailed(RunWatcher watcher, AtomicTest atomicTest
155163 */
156164 static void fireTestIgnored (Object runner , FrameworkMethod method ) {
157165 TestClass testClass = getTestClassOf (runner );
158- for (RunWatcher watcher : runWatcherLoader ) {
159- watcher .testIgnored (method , testClass );
166+ synchronized (runWatcherLoader ) {
167+ for (RunWatcher watcher : runWatcherLoader ) {
168+ watcher .testIgnored (method , testClass );
169+ }
160170 }
161171 }
162172
@@ -183,9 +193,11 @@ public static Object getTargetFor(FrameworkMethod method) {
183193 public static Optional <MethodWatcher > getAttachedWatcher (
184194 Class <? extends MethodWatcher > watcherType ) {
185195 Objects .requireNonNull (watcherType , "[watcherType] must be non-null" );
186- for (MethodWatcher watcher : methodWatcherLoader ) {
187- if (watcher .getClass () == watcherType ) {
188- return Optional .of (watcher );
196+ synchronized (methodWatcherLoader ) {
197+ for (MethodWatcher watcher : methodWatcherLoader ) {
198+ if (watcher .getClass () == watcherType ) {
199+ return Optional .of (watcher );
200+ }
189201 }
190202 }
191203 return Optional .empty ();
0 commit comments