Can someone explain me in simple terms, why does this code throw an exception, \"Comparison method violates its general contract!\", and how do I fix it?
pri
If compareParents(s1, s2) == -1 then compareParents(s2, s1) == 1 is expected. With your code it's not always true.
compareParents(s1, s2) == -1
compareParents(s2, s1) == 1
Specifically if s1.getParent() == s2 && s2.getParent() == s1. It's just one of the possible problems.
s1.getParent() == s2 && s2.getParent() == s1