Skip to content

Commit 9f1845d

Browse files
committed
refactor(internal): Override equals/hashCode/toString on RequestContext
The record carries a byte[] body, so the auto-generated record methods fall back to reference equality / identity hash for that component (SonarQube java:S6218). Override all three to compare bytes structurally via Arrays.equals/Arrays.hashCode, and have toString print the body length instead of the raw byte[]@hex.
1 parent bb93184 commit 9f1845d

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
package com.retailsvc.http.internal;
22

3+
import java.util.Arrays;
34
import java.util.Map;
5+
import java.util.Objects;
46

57
/**
68
* Immutable per-request data populated by {@link RequestPreparationFilter} and read by handlers via
79
* {@link com.retailsvc.http.Request}. Bound to a {@link ScopedValue} for the duration of a single
810
* request — never written to the {@code HttpExchange}'s context-shared attribute map.
11+
*
12+
* <p>{@code equals}, {@code hashCode}, and {@code toString} are overridden because the record
13+
* carries a {@code byte[]} component: the auto-generated implementations use reference equality on
14+
* arrays, which would treat structurally-equal contexts as different.
915
*/
1016
public record RequestContext(
11-
byte[] body, Object parsedBody, String operationId, Map<String, String> pathParameters) {}
17+
byte[] body, Object parsedBody, String operationId, Map<String, String> pathParameters) {
18+
19+
@Override
20+
public boolean equals(Object o) {
21+
if (this == o) {
22+
return true;
23+
}
24+
if (!(o instanceof RequestContext other)) {
25+
return false;
26+
}
27+
return Arrays.equals(body, other.body)
28+
&& Objects.equals(parsedBody, other.parsedBody)
29+
&& Objects.equals(operationId, other.operationId)
30+
&& Objects.equals(pathParameters, other.pathParameters);
31+
}
32+
33+
@Override
34+
public int hashCode() {
35+
return Objects.hash(Arrays.hashCode(body), parsedBody, operationId, pathParameters);
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "RequestContext[body=byte["
41+
+ (body == null ? 0 : body.length)
42+
+ "], parsedBody="
43+
+ parsedBody
44+
+ ", operationId="
45+
+ operationId
46+
+ ", pathParameters="
47+
+ pathParameters
48+
+ "]";
49+
}
50+
}

0 commit comments

Comments
 (0)