-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix bug in CtLineElementComparator #3519
Conversation
207771c
to
05efd09
Compare
Thanks for the fix! 2 failing tests are on generated code, we just have to regenerate the code. So only Overall, the fix is reasonable to me. |
if all constructors have invalid positions.
- Add missing newline add end of file
@monperrus merge/review ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for the update, see comment.
remove sysout
Thanks a lot Martin! |
Core Problem
As we saw in issue #3514 analyzing Palladio-SimuLizar produces jdk erros while sorting.
The reason for this is because the CtLineComparator does not follow the compareTo contract. This patch fixes the comparator.
Some Math Stuff
A comparator must follow the compareTo contract in java. The compareTo contract defines two formulas:
(1) antisymmetric sgn(x.compareTo(y)) == -sgn(y.compareTo(x))
(2) transitive (x.compareTo(y)>0 && y.compareTo(z)>0) => x.compareTo(z)>0
Assuming we have 3 points X,Y and Z and all points have invalid positions.
compareTo(X,Y)
== -1 ==> X < YcompareTo(Y,Z)
== -1 ==> Y < ZcompareTo(X,Z)
== -1 ==> X < ZLooks good till here but now:
compareTo(Z,X)
== -1 => Z<Xhere we violate the transitive requirement. Because Z is now less than X.
If we do the same after the change:
compareTo(X,Y)
== 0 ==> X=YcompareTo(Y,Z)
== 0 ==> Y=ZcompareTo(X,Z)
== 0 ==> X=ZcompareTo(Z,X)
== 0 ==> Z=XThe change still follows the antisymmetric contract, because sign(0)=0== -sign(0).
Consequences
Some testcases relay on the old sorting, because order was different. Some refactoring for the testcases is needed.
There is a risk, that some users have problems with new correct ordering.