Skip to content

Commit ce8b466

Browse files
committed
spotbugs: suppress USBR on equals/hashCode/canEqual/toString (Lombok)
Lombok-generated equals / hashCode / canEqual / toString carry the textbook polynomial-hash pattern (int result = 1; result = result * 59 + ...; return result;) which fb-contrib's USBR detector reads at the bytecode level as a store-then-immediate-return. SpotBugs core already skips its own detectors on members carrying @lombok.Generated (emitted by lombok.config's lombok.addLombokGeneratedAnnotation = true), but fb-contrib runs as a separate plugin family and does not honour that annotation. A method- name-based <Match> covers every member Lombok can emit. Clears 18 jllama findings at SpotBugs Max+Low. The collateral cost is small: any handwritten equals/hashCode/toString that genuinely stores-then-immediately-returns is either a debugger-friendly local- variable pattern or a micro-optimisation, both intentional here. https://claude.ai/code/session_01LzoKmqzgtQsELS5tsH4Wog
1 parent 9be73a3 commit ce8b466

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

spotbugs-exclude.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,36 @@ SPDX-License-Identifier: MIT
173173
<Method name="&lt;init&gt;"/>
174174
</Match>
175175

176+
<!--
177+
USBR_UNNECESSARY_STORE_BEFORE_RETURN on Lombok-generated equals / hashCode /
178+
canEqual / toString.
179+
180+
Lombok's @EqualsAndHashCode and @ToString annotation processors inject the
181+
textbook polynomial-hash bytecode pattern (and lombok.config already emits
182+
@lombok.Generated on every synthetic member via
183+
lombok.addLombokGeneratedAnnotation = true):
184+
185+
int result = 1;
186+
result = result * 59 + ($field == null ? 43 : $field.hashCode());
187+
...
188+
return result; // USBR fires here, on the istore_N / iload_N / ireturn triplet
189+
190+
SpotBugs core honours @lombok.Generated and skips its own detectors on those
191+
members, but the fb-contrib plugin's USBR detector does NOT &#x2014; fb-contrib
192+
is a separate plugin family with its own filter pipeline. Suppressing USBR on
193+
equals / hashCode / canEqual / toString matches every method name Lombok can
194+
emit. The collateral cost is small: any handwritten member of those four names
195+
that genuinely stores-then-immediately-returns is either a debugger-friendly
196+
local-variable pattern or a micro-optimisation, both intentional here.
197+
-->
198+
<Match>
199+
<Or>
200+
<Method name="equals"/>
201+
<Method name="hashCode"/>
202+
<Method name="canEqual"/>
203+
<Method name="toString"/>
204+
</Or>
205+
<Bug pattern="USBR_UNNECESSARY_STORE_BEFORE_RETURN"/>
206+
</Match>
207+
176208
</FindBugsFilter>

0 commit comments

Comments
 (0)