Skip to content

Comparable Contract Violation #15806

@sushovit29

Description

@sushovit29

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)

  • I made a backup of my libraries before testing the latest development version.
  • I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

  1. 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));
    }
}
  1. Compile it using below command:
    javac -cp "jablib\build\classes\java\main;jablib\build\dependencies\*" JabRefBug2.java
  2. 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.

Metadata

Metadata

Assignees

Labels

📌 Pinned📍 AssignedAssigned by assign-issue-action (or manually assigned)
No fields configured for code-quality.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions