Skip to content


Subversion checkout URL

You can clone with
Download ZIP


org.testng.internal.BaseTestMethod does respect general contract of Comparable #116

romlom opened this Issue · 3 comments

3 participants


from int java.lang.Comparable.compareTo(T o) javadoc:

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y.

So if we put y = x we got:

sgn( == -sgn(

So either throws exception either return 0



 public int compareTo(Object o) {
    int result = -2;
    Class<?> thisClass = getRealClass();
    Class<?> otherClass = ((ITestNGMethod) o).getRealClass();
    if (thisClass.isAssignableFrom(otherClass)) {
      result = -1;
    } else if (otherClass.isAssignableFrom(thisClass)) {
      result = 1;
    } else if (equals(o)) {
      result = 0;

    return result;

will return -1 when comparing object to itself.

I am reporting this because i got following exception:

java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeHi(
at java.util.ComparableTimSort.mergeAt(
at java.util.ComparableTimSort.mergeCollapse(
at java.util.ComparableTimSort.sort(
at java.util.ComparableTimSort.sort(
at java.util.Arrays.sort(
at java.util.Collections.sort(
at org.testng.internal.MethodInheritance.sortMethodsByInheritance(
at org.testng.internal.MethodInheritance.fixMethodInheritance(
at org.testng.internal.MethodHelper.sortMethods(
at org.testng.internal.MethodHelper.collectAndOrderMethods(
at org.testng.TestRunner.initMethods(
at org.testng.TestRunner.init(
at org.testng.TestRunner.init(
at org.testng.TestRunner.(
at org.testng.remote.RemoteTestNG$1.newTestRunner(
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(
at org.testng.SuiteRunner.init(
at org.testng.SuiteRunner.(
at org.testng.TestNG.createSuiteRunner(
at org.testng.TestNG.createSuiteRunners(
at org.testng.TestNG.runSuitesLocally(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(

Unfortunately, I did not manage to extract small example for testing purposes. But I hope issue is detailed enough.


Would it be possible to merge this? The fix looks simple enough and the issue is affecting people, as can be seen when querying Google.


Hi Lukáš,

Sure, but do you have a pull request? I don't see one.


Ah, my bad, I misread the page - I thought this was a pull request. I guess I'll have to provide one now, then. ;-)

@triceo triceo referenced this issue from a commit
@triceo triceo Fixes issue #116: org.testng.internal.BaseTestMethod does respect gen…
…eral contract of Comparable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.