Skip to content

Conversation

ic0ns
Copy link
Contributor

@ic0ns ic0ns commented Jun 30, 2025

Summary

  • Fixed SpotBugs issue EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC in ModifiableLengthField
  • Ensured equals() method maintains symmetry with ModifiableInteger and its subclasses
  • Added comprehensive test coverage for the symmetry fix

Changes

  • Modified ModifiableLengthField.equals() to handle comparison with different types correctly:
    • When comparing with another ModifiableLengthField: checks both value and reference equality
    • When comparing with other ModifiableInteger subclasses: only checks value equality for symmetry
  • Added ModifiableLengthFieldSymmetryTest with tests for:
    • Symmetry between ModifiableLengthField and ModifiableInteger
    • Handling of null values
    • Reference equality between ModifiableLengthField instances
    • Transitivity of equals
    • Edge cases and inheritance hierarchy

Test plan

  • Run existing ModifiableLengthFieldTest tests - all pass
  • Run new ModifiableLengthFieldSymmetryTest tests - all pass
  • Verify code compiles and passes spotless formatting
  • Confirm the fix resolves the SpotBugs warning

This fix ensures that if a.equals(b) returns true, then b.equals(a) also returns true, which is required by the equals() contract in Java.

- Modified equals() method to ensure symmetry with ModifiableInteger
- When comparing with another ModifiableLengthField, check both value and reference
- When comparing with other ModifiableInteger subclasses, only check value
- Added comprehensive tests to verify symmetry is maintained
- Fixes SpotBugs issue EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC
@ic0ns ic0ns closed this Jun 30, 2025
@ic0ns ic0ns deleted the fix-equals-symmetry branch June 30, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant