Commit 6ddd225
committed
lombok: force field-access in @EqualsAndHashCode / @tostring
Set lombok.equalsAndHashCode.doNotUseGetters = true and
lombok.toString.doNotUseGetters = true in lombok.config so Lombok-
generated equals/hashCode/toString read fields directly instead of
routing through `this.getX()`.
Motivation: several value classes expose getters that wrap their
`@Nullable T` field in Optional<T> (ChatRequest.getToolChoice,
ChatMessage.getToolCallId) or wrap a list field in
Collections.unmodifiableList + Optional (ChatMessage.getParts) for the
public-API contract. Those wrappers are not the equality contract.
The previous getter-routing behaviour caused two real defects:
1. fb-contrib OI_OPTIONAL_ISSUES_CHECKING_REFERENCE fired on every
Lombok-generated `this$x == null` branch when the getter returned an
Optional. Optional is the standard "never null" type, so the null
arm was dead code — fb-contrib correctly flagged it, contradicting
my prior characterisation as a "false positive".
2. ChatMessage.getParts() allocated a fresh
Collections.unmodifiableList AND a fresh Optional on every equals
or hashCode call. With field access these allocations disappear
entirely.
Switching is semantically identical: Optional.equals and
Collections.unmodifiableList(x).equals(...) both delegate to value-
based comparison of the underlying state. Verified by an audit covering
every Lombok-annotated class:
- Bucket 1 (verbatim getter): 11 classes — bit-identical output.
- Bucket 2 (Optional/unmodifiable wrapper getter): ChatRequest,
ChatMessage — both benefit from the switch.
- Bucket 3 (getter does non-trivial work equality should see): 0.
- Bucket 4 (@ToString-only identity classes): unaffected.
All value classes are `final`, so subclass-override of a getter cannot
change equality. callSuper=true chains
(InferenceParameters/ModelParameters) are unaffected because the parent
classes have no getter on their own included field. No test in the
repository pins a Lombok-format `Class(field=value)` substring.
SpotBugs Max+Low: 6 -> 2 findings (the 4 OI_OPTIONAL_ISSUES_CHECKING_REFERENCE
entries on ChatRequest/ChatMessage equals + hashCode clear). The
remaining 2 findings (DLS_DEAD_LOCAL_STORE on cancelHook,
SPP_FIELD_COULD_BE_STATIC on LlamaModel.ctx) are pre-existing and
unrelated.
Full test suite: 921 tests pass (the 1 error is the environmental
RerankingModelTest.setup UnsatisfiedLinkError — no native library on
this sandbox — not a regression).1 parent 4f1fbd7 commit 6ddd225
1 file changed
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
21 | 51 | | |
22 | 52 | | |
23 | 53 | | |
| |||
0 commit comments