Fix Comparable Contract Violation in SharedBibEntryData (#15806)#15842
Conversation
* Add an override to equals and hashCode function to satisfy Comparable contract. * Add SharedBibEntryDataTest covering equals/hashCode/compareTo consistency.
|
Hey @MateusLyoshka! 👋 Thank you for contributing to JabRef! We have automated checks in place, based on which you will soon get feedback if any of them are failing. We also use Qodo for review assistance. It will update your pull request description with a review help and offer suggestions to improve the pull request. After all automated checks pass, a maintainer will also review your contribution. Once that happens, you can go through their comments in the "Files changed" tab and act on them, or reply to the conversation if you have further inputs. You can read about the whole pull request process in our contribution guide. Please ensure that your pull request is in line with our AI Usage Policy and make necessary disclosures. |
Review Summary by QodoFix Comparable contract violation in SharedBibEntryData
WalkthroughsDescription• Implements equals() and hashCode() methods in SharedBibEntryData • Ensures consistency with existing compareTo() implementation • Adds comprehensive JUnit tests for contract compliance Diagramflowchart LR
A["SharedBibEntryData<br/>implements Comparable"] -->|missing| B["equals() and hashCode()"]
B -->|violates| C["Comparable contract"]
D["Add equals() method"] -->|compares| E["sharedID and version"]
F["Add hashCode() method"] -->|hashes| E
D -->|ensures| G["Contract compliance"]
F -->|ensures| G
H["Add unit tests"] -->|validates| G
File Changes1. jablib/src/main/java/org/jabref/model/entry/SharedBibEntryData.java
|
Code Review by Qodo
Context used✅ Tickets:
🎫 Comparable Contract Violation 1. Mutable equals/hashCode keys
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds value-based equality semantics to SharedBibEntryData and validates them with unit tests.
Changes:
- Implemented
equalsandhashCodeinSharedBibEntryDatabased onsharedIDandversion - Added JUnit tests covering equality/inequality and hash code behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| jablib/src/main/java/org/jabref/model/entry/SharedBibEntryData.java | Adds equals/hashCode implementations to support value-based comparisons |
| jablib/src/test/java/org/jabref/model/entry/SharedBibEntryDataTest.java | Introduces unit tests for the new equality and hashing behavior |
* upstream/main: (29 commits) Chore(deps): Bump dev.langchain4j:langchain4j-bom in /versions (JabRef#15853) Chore(deps): Bump org.glassfish.jaxb:jaxb-runtime in /versions (JabRef#15854) Chore(deps): Bump com.gradleup.shadow:shadow-gradle-plugin (JabRef#15852) Chore(deps): Bump com.gradleup.shadow:shadow-gradle-plugin (JabRef#15849) Chore(deps): Bump com.autonomousapps:dependency-analysis-gradle-plugin (JabRef#15850) Update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.5.6 (JabRef#15844) Fix reset and import of AiPreferences (JabRef#15843) Fix Comparable Contract Violation in SharedBibEntryData (JabRef#15806) (JabRef#15842) Chore(deps): Bump com.dlsc.gemsfx:gemsfx from 4.0.5 to 4.1.0 in /versions (JabRef#15841) Chore(deps): Bump jablib/src/main/resources/csl-styles (JabRef#15840) New Crowdin updates (JabRef#15839) Add group pseudonymization support (fixes JabRef#14117) (JabRef#15258) Feature parse MeSH terms in PubMed MEDLINE records (JabRef#15529) Fix/non latin author parsed as name prefix (JabRef#15823) Fix not on fx thread cleanup (JabRef#15835) Fix garbled BibEntry Javadoc example (JabRef#15834) Revert "Fix cleanup operationn setFiles not on fx thread causes exceptiosn" Revert "changelog" changelog Fix cleanup operationn setFiles not on fx thread causes exceptiosn ...
#15806 Fix Comparable contract violation in SharedBibEntryData
Closes #15806
SharedBibEntryDataimplementsComparable<SharedBibEntryData>but was missingequalsandhashCodeimplementations, violating the contract thatcompareToreturning 0 must be consistent withequals. Both methods were added along with tests covering their consistency.Run
SharedBibEntryDataTest— all 4 tests should pass. Alternatively, verify manually that two defaultSharedBibEntryDatainstances are equal and have the same hash code.Note:
SharedBibEntryDatais only active in shared SQL database mode. Manual testing in a live shared database setup is impractical for this fix. The behavior is fully covered by the added JUnit tests.Claude Code (model claude-sonnet-4-6)
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)