From ae313513dd84c0bf618c178b42b5bf41c701f548 Mon Sep 17 00:00:00 2001 From: Gerd Riesselmann Date: Thu, 19 Dec 2019 12:16:27 +0100 Subject: [PATCH] Avoid possible comparison contract violation (#9883) 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 #9881 Modification: Return equality instead of less than on same path length. Result: Fixes #9881. --- .../netty/handler/codec/http/cookie/ClientCookieEncoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java index 5c84f86156..ee986fd4d6 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java @@ -106,9 +106,9 @@ public final class ClientCookieEncoder extends CookieEncoder { 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; }; /**