Skip to content

Commit

Permalink
Avoid possible comparison contract violation (netty#9883)
Browse files Browse the repository at this point in the history

Motivation:

The current implementation causes IllegalArgumetExceptions to be thrown on Java 11.

The current implementation would violate comparison contract for two cookies C1 and C2 with same path length, since C1 < C2 and C2 < C1. Returning 0 (equality) does not since C1 == C2 and C2 == C1. See netty#9881

Modification:

Return equality instead of less than on same path length.

Result:

Fixes netty#9881.
  • Loading branch information
gerdriesselmann authored and normanmaurer committed Dec 19, 2019
1 parent 95b8db0 commit f995426
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public int compare(Cookie c1, Cookie c2) {
if (diff != 0) {
return diff;
}
// Rely on Java's sort stability to retain creation order in cases where
// Rely on Arrays.sort's stability to retain creation order in cases where
// cookies have same path length.
return -1;
return 0;
}
};

Expand Down

0 comments on commit f995426

Please sign in to comment.