From 7180ae4d60a5f67c47c3258e93f28cf604155d9b Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Thu, 21 Mar 2024 21:44:50 +0530 Subject: [PATCH] Tweaks around accessing SuiteResult MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3078 Following changes were made: * Removed the lock based synchronization around SuiteResult because it’s already backed by a SynchronizedMap from Collections. * Altered the getter such that it returns back a regular linkedHashMap (without the synchronisation Because users are expected ONLY to iterate on it and NOT change its state) * Also just to ensure that users don’t garble the Suite result, wrapping it with an UnModifiableMap --- testng-core/src/main/java/org/testng/SuiteRunner.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testng-core/src/main/java/org/testng/SuiteRunner.java b/testng-core/src/main/java/org/testng/SuiteRunner.java index 41244e821..452e57112 100644 --- a/testng-core/src/main/java/org/testng/SuiteRunner.java +++ b/testng-core/src/main/java/org/testng/SuiteRunner.java @@ -34,8 +34,7 @@ public class SuiteRunner implements ISuite, ISuiteRunnerListener { private static final String DEFAULT_OUTPUT_DIR = "test-output"; - private final Map suiteResults = - Collections.synchronizedMap(Maps.newLinkedHashMap()); + private final Map suiteResults = Maps.newLinkedHashMap(); private final List testRunners = Lists.newArrayList(); private final Map, ISuiteListener> listeners = Maps.newLinkedHashMap(); @@ -514,7 +513,9 @@ public String getOutputDirectory() { @Override public Map getResults() { - return suiteResults; + // Just to ensure that we guard the internals of the suite results we now wrap it + // around with an unmodifiable map. + return Collections.unmodifiableMap(suiteResults); } /**