#2340 Comparison method violates its general contract!

ahhatem Mon 1 Sep 2014

Hi,

One of the exceptions I always find hard to track is:

sys::ArgErr: java.lang.IllegalArgumentException: Comparison method violates its general contract! 

Usually, it is thrown without any kind of details regarding the file throwing the error or the line or the method name. Can someone give me a hint on How can I find that?

SlimerDude Mon 1 Sep 2014

Wow - I've never seen that!

But it's a Java exception, not a Fantom one. A quick google gives me:

Java error: Comparison method violates its general contract

It seems to mean that your comparison method doesn't do what it's supposed to do.

Note there's also an answer that states the exception is specific to JREs > 1.6.

SlimerDude Mon 1 Sep 2014

Um, if I wasn't clear, the error is probably in a Obj.compare() or List.sort() method.

Are you sure there's nothing else in the stack trace?

ahhatem Mon 1 Sep 2014

Nope, no stacktraces.

I understand the problem, I previously managed to fix things by guessing, but I was wondering if I could somehow get the stacktrace so I can be sure where exactly does the error happen.

Hertz Mon 1 Sep 2014

If the code is not too big can you post it or a link to it. I want to try it out myself

ahhatem Tue 2 Sep 2014

Unfortunately the code is big and belongs to my employer so I can't share it but I will try to make a test case showing the error if possible.

brian Fri 5 Sep 2014

That exception means you have a bug in a compare() method where you don't consistently order your objects. It typically always happens during a sort operation and is raised by the underlying Java sorting library

Login or Signup to reply.