1 From 49a74350016b59c4cca054c5802b4437c0b3857f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolan.mcnamara@collabora.com>
3 Date: Wed, 4 Oct 2023 15:19:13 +0100
4 Subject: [PATCH] cid#1545249 Bad bit shift operation
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19
11 If the promoted type of the left-hand operand is int, only the five
12 lowest-order bits of the right-hand operand are used as the shift
13 distance. It is as if the right-hand operand were subjected to a bitwise
14 logical AND operator & (ยง15.22.1) with the mask value 0x1f (0b11111).
15 The shift distance actually used is therefore always in the range 0 to
18 so a >>> of 32 is the same as >>> 0 so this is
19 result = 31 * result + (maxFrameSize ^ maxFrameSize);
21 result = 31 * result + (0);
23 which all looks a bit dubious.
25 Working theory from https://gerrit.libreoffice.org/c/core/+/157571/1 is
26 that at some point maxFrameSize was a long value, and then got changed
27 to an int, but the hashCode() was not updated and should now read as
30 result = 31 * result + maxFrameSize;
32 src/main/java/org/java_websocket/drafts/Draft_6455.java | 2 +-
33 1 file changed, 1 insertion(+), 1 deletion(-)
35 diff --git a/src/main/java/org/java_websocket/drafts/Draft_6455.java b/src/main/java/org/java_websocket/drafts/Draft_6455.java
36 index 1e08448..635fa1f 100644
37 --- a/src/main/java/org/java_websocket/drafts/Draft_6455.java
38 +++ b/src/main/java/org/java_websocket/drafts/Draft_6455.java
39 @@ -1150,7 +1150,7 @@ public class Draft_6455 extends Draft {
40 public int hashCode() {
41 int result = negotiatedExtension != null ? negotiatedExtension.hashCode() : 0;
42 result = 31 * result + (protocol != null ? protocol.hashCode() : 0);
43 - result = 31 * result + (maxFrameSize ^ (maxFrameSize >>> 32));
44 + result = 31 * result + maxFrameSize;