why does my compare method throw exception — Comparison method violates its general contract!

I suspect the problem occurs when neither value is sponsored. That will return 1 whichever way you call it, i.e. x1.compare(x2) == 1 x2.compare(x1) == 1 That’s invalid. I suggest you change this: object1.getSponsored() && object2.getSponsored() to object1.getSponsored() == object2.getSponsored() in both places. I would probably actually extract this out a method with this signature … Read more