diff --git a/testng-core/src/main/java/org/testng/internal/BaseTestMethod.java b/testng-core/src/main/java/org/testng/internal/BaseTestMethod.java index 503e58a99..c0ad3379f 100644 --- a/testng-core/src/main/java/org/testng/internal/BaseTestMethod.java +++ b/testng-core/src/main/java/org/testng/internal/BaseTestMethod.java @@ -6,13 +6,14 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.testng.IClass; @@ -832,7 +833,7 @@ private IRetryAnalyzer getRetryAnalyzerConsideringMethodParameters(ITestResult t return this.m_retryAnalyzer; } - final String keyAsString = getSimpleName() + "#" + hashParameters(tr); + final String keyAsString = getSimpleName() + "#" + parameterId(tr); return m_testMethodToRetryAnalyzer.computeIfAbsent( keyAsString, key -> { @@ -842,9 +843,13 @@ private IRetryAnalyzer getRetryAnalyzerConsideringMethodParameters(ITestResult t }); } - private int hashParameters(ITestResult itr) { - Object[] parameters = itr.getParameters(); - return Objects.hash(parameters); + private final Map parameters = + new ConcurrentHashMap<>(); + + private String parameterId(ITestResult itr) { + IObject.IdentifiableArrayObject parameter = + new IObject.IdentifiableArrayObject(itr.getParameters()); + return parameters.computeIfAbsent(parameter, Function.identity()).getInstanceId(); } private static boolean isNotParameterisedTest(ITestResult tr) { diff --git a/testng-core/src/main/java/org/testng/internal/IObject.java b/testng-core/src/main/java/org/testng/internal/IObject.java index 04c04946f..4389b6ec0 100644 --- a/testng-core/src/main/java/org/testng/internal/IObject.java +++ b/testng-core/src/main/java/org/testng/internal/IObject.java @@ -1,5 +1,6 @@ package org.testng.internal; +import java.util.Arrays; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -113,4 +114,36 @@ public int hashCode() { return Objects.hash(instanceId); } } + + /** + * A wrapper class that wraps around an array and associates a unique Id that can be used as a key + * for the array. + */ + class IdentifiableArrayObject { + + private final String instanceId = UUID.randomUUID().toString(); + + private final Object[] parameters; + + public IdentifiableArrayObject(Object[] parameters) { + this.parameters = parameters; + } + + public String getInstanceId() { + return instanceId; + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null || getClass() != object.getClass()) return false; + IdentifiableArrayObject that = (IdentifiableArrayObject) object; + return Arrays.equals(parameters, that.parameters); + } + + @Override + public int hashCode() { + return Arrays.hashCode(parameters); + } + } }