Comparable Contract Violation
JabRef version
Latest development branch build (please note build date below)
Operating system
Windows
Details on version and operating system
Windows 11 Home 25H2 26200.8457, Jabref forked and built on 22/05/2026
Checked with the latest development build (copy version output from About dialog)
- [x] I made a backup of my libraries before testing the latest development version.
- [x] I have tested the latest development version and the problem persists
Steps to reproduce the behaviour
- Add the below JabRefBug2.java file to base "jabref" folder
// Bug 2: SharedBibEntryData violates Comparable/equals consistency
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.SharedBibEntryData;
public class JabRefBug2 {
public static void main(String[] args) {
BibEntry entry1 = new BibEntry();
BibEntry entry2 = new BibEntry("hi!");
SharedBibEntryData data1 = entry1.getSharedBibEntryData();
SharedBibEntryData data2 = entry2.getSharedBibEntryData();
boolean isCompareZero = (data1.compareTo(data2) == 0);
boolean isEqual = data1.equals(data2);
// If compareTo is 0, equals() MUST be true. This prints false, exposing the bug.
System.out.println("Contract upheld? " + (isCompareZero == isEqual));
}
}
- Compile it using below command:
javac -cp "jablib\build\classes\java\main;jablib\build\dependencies\*" JabRefBug2.java - Run it using below command:
C:\git-repositories\jabref>java -cp ".;jablib\build\classes\java\main;jablib\build\dependencies\*" JabRefBug2
Current output: Contract upheld? false
Appendix
Found this bug using automated contract testing with Randoop and tested using above Minimal Reproducible Example (MRE). The SharedBibEntryData class implements the Comparable interface. The official Java documentation strictly advises that x.compareTo(y) == 0 should have the exact same boolean result as x.equals(y). Randoop found instances where two SharedBibEntryData objects are considered "equal" by compareTo, but "not equal" by .equals() (or vice versa). This will cause sorting algorithms (like Collections.sort()) to behave unpredictably in the JabRef UI.
/assign-me
👋 Hey @MateusLyoshka, thank you for your interest in this issue! 🎉
We're excited to have you on board. Start by exploring our Contributing guidelines, and set up your local development workspace by following the steps in our workspace setup guidelines to get started smoothly.
For questions on JabRef functionality, you can consult the JabRef Guru. For questions related to the codebase, please start using DeepWiki.
In case you encounter failing tests during development, please check our developer FAQs!
Still facing issues or having more questions? Feel free to ask here on GitHub or on JabRef's Gitter chat. Please don't hesitate to open a (draft) pull request early on to show the direction you are heading towards if unsure.
Happy coding! 🚀
Have fun @MateusLyoshka! Clean data structures is also our aim. We spend dozens of hours to work on tnis 2015 to maybe 2018. Now its time for a new ara of students to take over. Will take maybe 1 year to fix the whole data model throughout the code, but yeah, go ahead! Please remember test-driven development with all functionality of JabRef (imports, exports, GUI, CLI, Browser Plugin, Word Plugin, HTTP Server, ...). Nice challenge!
We think that this issue was fixed. Please head to https://builds.jabref.org/main to download a development build and try it out.
For any feedback, add a comment to the pull request at https://github.com/JabRef/jabref/pull/15842.