Skip to content

Commit 4e4086a

Browse files
Fix missing hashCode implementations for SpotBugs compliance (#4316)
* Fix SpotBugs warnings for missing or inconsistent hashCode Implemented proper hashCode() methods in classes overriding equals(): - Geofence: Uses ID, radius, expiration, and location coordinates. - PropertyBase: Uses name. - Font: Uses font properties (face, size, style) or native font hash. - Border: Uses type, color, thickness, arc, etc. - Style: Uses visual properties (colors, font, background). - TarEntry: Added equals(Object) and hashCode based on header name. - CustomFont: Uses charset and cutOffsets. - Transform: Uses type and transformation matrix values. - CSSBorder (and inner classes): Uses identity hash or field hashes. - RoundBorder/RoundRectBorder: Uses identity hash (consistent with equals). - ImageDownloadService: Uses cacheId. - Layouts (Border, Box, Flow, Grid, Table): Use layout properties. * Fix SpotBugs warnings: Implement proper hashCode and equals for core classes - Implemented consistent `hashCode()` and `equals()` for: - `Geofence`: uses id, location, radius, expiration. - `PropertyBase`: uses name. - `Font`: uses native font or attributes. - `Border` / `CSSBorder` / `RoundBorder`: uses fields or identity where appropriate. - `Style`: manual hash calculation for primitive arrays (margin/padding) to avoid missing Arrays utility in CLDC. - `TarEntry`: added `equals(Object)` override and `hashCode` based on header name. - `Transform`: uses type and matrix values. - `ImageDownloadService`: uses cacheId. - `BoxLayout`: added `align` to equals/hashCode to fix layout update issues. - `BorderLayout`, `FlowLayout`, `GridLayout`, `TableLayout`: uses configuration fields. - Fixed `BoxLayout` equality check to include alignment, resolving layout update regression. - Manual array hashing in `Style` ensures CLDC 1.1 compatibility. * Fix SpotBugs hashCode warnings while preserving legacy behavior - Reverted `Style.hashCode` to use `System.identityHashCode(this)` to prevent regressions in layout and caching caused by value-based hashing of mutable UI state. - Reverted `BoxLayout` equality to ignore `align` (matching previous behavior) to resolve test failures. - Implemented consistent `hashCode()` for: - `Geofence`: uses id, location, radius, expiration. - `PropertyBase`: uses name. - `Font`: uses native font or attributes. - `Border` / `CSSBorder` / `RoundBorder`: uses fields or identity where appropriate. - `TarEntry`: added `equals(Object)` override and `hashCode`. - `Transform`: uses type and matrix values. - `ImageDownloadService`: uses cacheId. - `BorderLayout`, `FlowLayout`, `GridLayout`, `TableLayout`: uses configuration fields. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 1680c6e commit 4e4086a

File tree

17 files changed

+461
-295
lines changed

17 files changed

+461
-295
lines changed

CodenameOne/src/com/codename1/io/services/ImageDownloadService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,13 @@ public boolean equals(Object o) {
934934
((ImageDownloadService) o).cacheId.equals(cacheId);
935935
}
936936

937+
/**
938+
* {@inheritDoc}
939+
*/
940+
public int hashCode() {
941+
return cacheId != null ? cacheId.hashCode() : 0;
942+
}
943+
937944
/**
938945
* @return the maintainAspectRatio
939946
*/

0 commit comments

Comments
 (0)