jabref icon indicating copy to clipboard operation
jabref copied to clipboard

Collection Reflexivity Violation

Open sushovit29 opened this issue 6 months ago • 10 comments

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

  1. Add the below JabRefBug1.java file to base "jabref" folder
// Bug 1: getFieldValues() violates equals() reflexivity
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.types.StandardEntryType;
import java.util.Collection;

public class JabRefBug1 {
    public static void main(String[] args) {
        BibEntry entry = new BibEntry(StandardEntryType.Article);

        Collection<String> values = entry.getFieldValues();
        
        // This should ALWAYS print true in Java, but it evaluates to false
        System.out.println("Is collection equal to itself? " + values.equals(values));
    }
}
  1. Compile it using below command: javac -cp "jablib\build\classes\java\main;jablib\build\dependencies\*" JabRefBug1.java
  2. Run it using below command: C:\git-repositories\jabref>java -cp ".;jablib\build\classes\java\main;jablib\build\dependencies\*" JabRefBug1

Current output: Is collection equal to itself? false

Appendix

Found this bug using automated contract testing with Randoop and tested using above Minimal Reproducible Example (MRE). When we call bibEntry.getFieldValues(), it returns a Collection. However, this collection violates the fundamental Java Object.equals() contract, which states an object must be equal to itself. Because it returns false, placing these collections into HashSets or HashMaps could cause silent data corruption or memory leaks in JabRef.

sushovit29 avatar May 22 '26 08:05 sushovit29

I don't see the practicality of this issue

faneeshh avatar May 22 '26 08:05 faneeshh

I don't see the practicality of this issue

true, maybe its just a best practices suggestion.

subhramit avatar May 22 '26 11:05 subhramit

Do you have any ideas why this might happen, sushovit29?

InAnYan avatar May 22 '26 22:05 InAnYan

Mh, as JabRef is not just a hobby project, but also claims to be used for teaching SE i think this issue is still valid, even though the parcticallity is not obvious. Nevertheless, not high priority, but valid imho.

calixtus avatar May 23 '26 14:05 calixtus

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!

koppor avatar May 26 '26 18:05 koppor

/assign-me

MateusLyoshka avatar Jun 03 '26 01:06 MateusLyoshka

Thank you for your continued work in JabRef. At this point, you probably already know the basics and the important links. If not, our contributing guidelines is the place you should go to.

At this point in time, you raised 1 pull request(s) of which 100% (1/1) have been merged.

jabref-machine avatar Jun 03 '26 01:06 jabref-machine

⏰ Assignment Reminder

Hi @MateusLyoshka, this is a friendly reminder about your assignment to this issue.

[!WARNING] This issue will be automatically unassigned in 7 days if there's no activity.

Remember that you can ask the JabRef Guru or DeepWiki about anything regarding JabRef. Additionally, our contributing guide has hints on creating a pull request and a link to our Gitter chat.

How to keep your assignment


If you are working on it, you can prevent automatic unassignment by:

  • Submitting a draft pull request with your progress within 7 days
  • Asking for the 📌 Pinned label if you need more time

We appreciate your contribution and are here to help if needed!

github-actions avatar Jun 09 '26 13:06 github-actions

It is important to keep memory and performance in mind as this is a critical section in the code and consumers just merely iterate over the collection.

Siedlerchr avatar Jun 16 '26 17:06 Siedlerchr

We saw that this causes much effort when working on it - https://github.com/JabRef/jabref/pull/15986#issuecomment-4750182642

Since no user of JabLib made this request @sushovit29, we closed it.

koppor avatar Jun 22 '26 07:06 koppor