Skip to content

Commit d4e712d

Browse files
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.
1 parent e1bf4ba commit d4e712d

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

CodenameOne/src/com/codename1/ui/layouts/BoxLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ public String toString() {
520520
* {@inheritDoc}
521521
*/
522522
public boolean equals(Object o) {
523-
return super.equals(o) && axis == ((BoxLayout) o).axis && align == ((BoxLayout) o).align;
523+
return super.equals(o) && axis == ((BoxLayout) o).axis;
524524
}
525525

526526
@Override
527527
public int hashCode() {
528-
return super.hashCode() ^ axis ^ align;
528+
return super.hashCode() ^ axis;
529529
}
530530
}

CodenameOne/src/com/codename1/ui/plaf/Style.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,29 +3158,7 @@ public boolean equals(Object obj) {
31583158

31593159
@Override
31603160
public int hashCode() {
3161-
int hash = 7;
3162-
hash = 89 * hash + this.fgColor;
3163-
hash = 89 * hash + this.fgAlpha;
3164-
hash = 89 * hash + this.bgColor;
3165-
hash = 89 * hash + com.codename1.compat.java.util.Objects.hashCode(this.font);
3166-
hash = 89 * hash + com.codename1.compat.java.util.Objects.hashCode(this.bgImage);
3167-
hash = 89 * hash + this.transparency;
3168-
hash = 89 * hash + this.opacity;
3169-
hash = 89 * hash + this.backgroundType;
3170-
hash = 89 * hash + this.backgroundAlignment;
3171-
if (this.padding != null) {
3172-
for (float p : this.padding) {
3173-
hash = 89 * hash + Float.floatToIntBits(p);
3174-
}
3175-
}
3176-
if (this.margin != null) {
3177-
for (float m : this.margin) {
3178-
hash = 89 * hash + Float.floatToIntBits(m);
3179-
}
3180-
}
3181-
hash = 89 * hash + com.codename1.compat.java.util.Objects.hashCode(this.border);
3182-
hash = 89 * hash + this.align;
3183-
return hash;
3161+
return System.identityHashCode(this);
31843162
}
31853163

31863164
}

0 commit comments

Comments
 (0)