Skip to content

Fix numeric sorting for citationcount, day, and dayfiled columns - #17649

Merged
Siedlerchr merged 6 commits into
JabRef:mainfrom
kpunia306:fix-numeric-sorting-fields
Nov 5, 2026
Merged

Siedlerchr merged 6 commits into
JabRef:mainfrom
kpunia306:fix-numeric-sorting-fields

Conversation

@kpunia306

@kpunia306 kpunia306 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #17459

In StandardField.java, the fields CITATIONCOUNT, DAY, and DAYFILED were missing FieldProperty.NUMERIC. Because of this, their table columns sorted values alphabetically (e.g. 1, 10, 2, 200, 9) rather than numerically (1, 2, 9, 10, 200).

Following maintainer guidance in #17459 and #17469, this PR:

  1. Adds FieldProperty.NUMERIC to CITATIONCOUNT, DAY, and DAYFILED in StandardField.java.
  2. Adds unit test coverage in StandardFieldTest.java verifying isNumeric() on all updated fields.
  3. Adds a changelog entry to CHANGELOG.md.

Steps to test

  1. Open JabRef.
  2. In Settings -> Entry Table, add columns for day or citationcount.
  3. Create entries with numerical values (e.g. 1, 2, 9, 10, 20).
  4. Click the column header to sort. Notice they sort in numerical order.

Related issues and pull requests

Closes #17459

AI usage

I used Antigravity / Gemini 3.8 Flash (Medium) to assist with finding the enum in StandardField.java and preparing unit tests in StandardFieldTest.java. I reviewed, tested, and verified all changes locally.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions

Copy link
Copy Markdown
Contributor

Hey @kpunia306! 👋

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.

@jabref-machine jabref-machine added the dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) label Oct 31, 2026
@github-actions github-actions Bot added size: small good first issue An issue intended for project-newcomers. Varies in difficulty. component: maintable status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed component: maintable labels Oct 31, 2026
@ThiloteE

ThiloteE commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Hello @kpunia306 what I tried to say at #17476 (comment) still applies, albeit my wording might have been too generic to convey my meaning. I think we all would benefit from finding out why those field are not numeric in the first place. Is there a reason for it? One reason might be, that those fields are defined in the bibtex or biblatex standard to be non-numeric and since JabRef follows those standards, it is so. Another reason might be that people that write articles and books don't follow those standards perfectly, so we might find entries out there in the wild containing non-numeric data in those fields, such as for the day field it could be "tuesday", "wednesday" or maybe even the days of the week in a different language.

So what I think should be done to make sure we do the right thing here is to first look at the definitions, such as in the biblatex package documentation at https://ctan.org/pkg/biblatex and https://ctan.org/pkg/tamethebeast and then to find some real entries uploaded to scientific journals or data providers like Crossref. If you can find one or multiple entries WITH numeric field content and some others WITHOUT numeric field content, then fixing this becomes more complicated.

@kpunia306

Copy link
Copy Markdown
Contributor Author

Thank you for pointing this out @ThiloteE! I looked into the official BibTeX/BibLaTeX specifications and how JabRef's comparator handles these fields:

  1. CITATIONCOUNT:

    • This is in the JabRef-specific fields region in StandardField.java. It is not part of BibLaTeX/BibTeX standards, but populated by JabRef citation fetchers (Semantic Scholar, CrossRef) or entered manually. Citation counts are inherently integer values (0, 1, 9, 200...), so treating this as numeric makes direct sense.
  2. DAY and DAYFILED:

    • According to the biblatex manual (§2.2.2 Data Fields), day is explicitly defined as an integer ("The day of the month, given as an integer").
    • dayfiled is the IEEEtran counterpart for patent filing dates, parallel to yearfiled. In JabRef, YEARFILED is already marked with FieldProperty.NUMERIC (line 139 of StandardField.java).
  3. CHAPTER and PART:

    • In the biblatex manual, chapter and part are classified as literal rather than integer. While users often write numeric chapter numbers (1, 2, 10), they can occasionally contain strings (e.g. section titles or Roman numerals).
  4. Fallback Behavior in NumericFieldComparator:

    • Looking at NumericFieldComparator.java (lines 20–59), when a field has FieldProperty.NUMERIC, it attempts to parse the integer via StringUtil.intValueOf(). If the value contains non-numeric text (e.g., "Tuesday" or a text string), it catches NumberFormatException and safely falls back to standard lexicographical string comparison (val1.compareTo(val2)).
    • This is the exact same pattern used for EDITION and VOLUME, which are also marked FieldProperty.NUMERIC despite sometimes containing textual ordinals in the wild.

If you prefer to keep literal fields strictly untouched, I am very happy to remove CHAPTER and PART from this PR and keep the fix focused strictly on CITATIONCOUNT, DAY, and DAYFILED! What would you prefer?

@kpunia306

Copy link
Copy Markdown
Contributor Author

Fair point, sorry about that! To keep it simple: I think citationcount, day, and dayfiled definitely make sense as numeric. Happy to revert chapter and part so we keep the PR minimal. Let me know if that works and I'll update the branch!

@ThiloteE ThiloteE removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 1, 2026
@ThiloteE
ThiloteE marked this pull request as draft November 1, 2026 09:30
@ThiloteE

ThiloteE commented Nov 1, 2026

Copy link
Copy Markdown
Member

@kpunia306 kpunia306 changed the title Fix numeric sorting for citationcount, day, dayfiled, chapter, and part columns Fix numeric sorting for citationcount, day, and dayfiled columns Nov 2, 2026
@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete component: maintable labels Nov 2, 2026
@kpunia306
kpunia306 force-pushed the fix-numeric-sorting-fields branch from bd8c0b9 to 1674d19 Compare November 2, 2026 20:31
@github-actions github-actions Bot added component: maintable and removed component: maintable status: changes-required Pull requests that are not yet complete labels Nov 2, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (3)

Grey Divider


Remediation recommended

1. Large citation counts sort before zero 🐞 Bug
Description
NumericFieldComparator.compare subtracts parsed integers, while StringUtil.intValueOf can
overflow when parsing digit-only values. With the new numeric property on CITATIONCOUNT, a column
containing 2147483648 and 0 can place the larger count first in ascending order.
Code

jablib/src/main/java/org/jabref/model/entry/field/StandardField.java[147]

+    CITATIONCOUNT("citationcount", FieldProperty.NUMERIC),
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Marking citation counts numeric routes their table column through an integer comparator that can misorder large digit-only values because parsing and subtraction overflow.
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/util/comparator/NumericFieldComparator.java[16-36]
- jablib/src/main/java/org/jabref/logic/util/strings/StringUtil.java[444-463]
## Recommended Fix
Use an overflow-safe numeric comparison for digit-only values, including values outside the `int` range. Add a sorting test with `0` and `2147483648`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View medium (1)
2. Mixed numeric and text values give an inconsistent citation count sort 🐞 Bug
Description
EntryComparator parses both values with Integer.parseInt only when both parse, and otherwise
falls back to string comparison for that pair, so a column mixing integers and non-integer text gets
a non-transitive order. The PR newly sets NUMERIC on CITATIONCOUNT, DAY and DAYFILED, which
exposes these columns to that mixed-value path. Entries with values such as "1a" or "n/a" can then
produce an undefined sort order or make the list sort throw.
Code

jablib/src/main/java/org/jabref/model/entry/field/StandardField.java[147]

+    CITATIONCOUNT("citationcount", FieldProperty.NUMERIC),
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In `EntryComparator`, the `sortField.isNumeric()` branch parses both values as integers and silently falls back to lexical comparison for any pair where one value is not an integer. For mixed columns (for example `citationcount` values "10", "9", "1a") this yields a non-transitive comparator, so the sort order is undefined and may throw. The PR now marks `CITATIONCOUNT`, `DAY` and `DAYFILED` as `NUMERIC`, which exposes these columns to this path.
## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/bibtex/comparator/EntryComparator.java[79-90]
- jablib/src/main/java/org/jabref/logic/bibtex/comparator/FieldComparator.java[46]
## Recommended Fix
Make the numeric branch a total order. Parse each value independently. Sort parsable values numerically and place non-parsable values after all numeric values, comparing them lexically among themselves. Keep the current null handling. Add a unit test that sorts a list with values such as "10", "9", "1a" and null, and checks that the sort completes and is consistent.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



View low (1)
Informational
3. Day and citation count lose LaTeX and whitespace cleanup 🐞 Bug
Description
Adding FieldProperty.NUMERIC to DAY, DAYFILED and CITATIONCOUNT also changes
FieldFactory.isLatexField (these fields are now not LaTeX fields) and
FieldFactory.getNotTextFields (these fields are now excluded from text cleanups). As a result,
LatexIntegrityChecker, AmpersandChecker and BibStringChecker no longer check these fields, and
FieldFormatterCleanup and NormalizeWhitespacesCleanup no longer process them. The PR description
and the changelog only mention sorting, so this broader side effect is not called out.
Code

jablib/src/main/java/org/jabref/model/entry/field/StandardField.java[R36-37]

+    DAY("day", FieldProperty.NUMERIC),
+    DAYFILED("dayfiled", FieldProperty.NUMERIC),
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Adding FieldProperty.NUMERIC to DAY, DAYFILED and CITATIONCOUNT silently changes isLatexField and getNotTextFields, so integrity checks and text cleanups stop processing those fields.
## Fix Focus Areas
- jablib/src/main/java/org/jabref/model/entry/field/StandardField.java[36-37]
- jablib/src/main/java/org/jabref/model/entry/field/FieldFactory.java[196-212]
## Recommended Fix
Confirm that skipping LaTeX checks and text cleanup for these numeric fields is intended. If it is, add a short note to the PR description. If it is not, decouple sorting from these checks, for example by checking the sort property separately in the comparator and not via NUMERIC in FieldFactory.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions github-actions Bot added component: maintable and removed component: maintable status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 5, 2026
Siedlerchr
Siedlerchr previously approved these changes Nov 5, 2026
@Siedlerchr
Siedlerchr enabled auto-merge November 5, 2026 20:02
Siedlerchr
Siedlerchr previously approved these changes Nov 5, 2026
@Siedlerchr
Siedlerchr enabled auto-merge November 5, 2026 20:25
@github-actions github-actions Bot added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 5, 2026
@Siedlerchr
Siedlerchr added this pull request to the merge queue Nov 5, 2026
@github-actions github-actions Bot added status: to-be-merged PRs which are accepted and should go into the merge-queue. and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 5, 2026
Merged via the queue into JabRef:main with commit 4bedad1 Nov 5, 2026
@jabref-machine

Copy link
Copy Markdown
Collaborator

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Nov 5, 2026
Siedlerchr added a commit that referenced this pull request Nov 6, 2026
…n-list

* upstream/main: (74 commits)
  Reduce layout jump of tags editors (#17555)
  [Port to main] Chore(deps-dev): Bump @modelcontextprotocol/server from 2.0.0 to 2.4.0 (#17670)
  Make arXiv fallback title matching locale independent (#17652)
  Chore(deps): Bump org.eclipse.jgit:org.eclipse.jgit.ssh.apache.agent from 7.8.0.202609011348-r to 7.8.1.202611041320-r in /versions (#17726)
  Chore(deps): Bump org.eclipse.jgit:org.eclipse.jgit from 7.8.0.202609011348-r to 7.8.1.202611041320-r in /versions (#17727)
  Chore(deps): Bump org.eclipse.jgit:org.eclipse.jgit.ssh.apache from 7.8.0.202609011348-r to 7.8.1.202611041320-r in /versions (#17728)
  Chore(deps): Bump com.dlsc.gemsfx:gemsfx from 4.6.0 to 4.7.0 in /versions (#17729)
  New Crowdin updates (#17725)
  chore(deps): update dependency com.nimbusds:oauth2-oidc-sdk to v11.39 (#17723)
  Fix numeric sorting for citationcount, day, and dayfiled columns (#17649)
  Preserve syntax highlighting when copying BibTeX in Source tab (#17392) (#17441)
  Chore(deps): Bump com.dlsc.gemsfx:gemsfx from 4.5.0 to 4.6.0 in /versions (#17721)
  Chore(deps): Bump com.konghq:unirest-java-core from 4.11.2 to 4.11.3 in /versions (#17719)
  Chore(deps): Bump org.graalvm.sdk:nativeimage from 25.4.4.1.1 to 25.5.5.0.3 in /versions (#17718)
  Chore(deps): Bump com.konghq:unirest-modules-gson from 4.11.2 to 4.11.3 in /versions (#17720)
  New Crowdin updates (#17715)
  chore(deps): update dependency org.eclipse.jgit:org.eclipse.jgit.pgm to v7.8.1.202611041320-r (#17712)
  Restrict consistency check columns to the fields of a .bst style (#17710)
  Remove OCR language handling from DoclingEngine (#17674)
  Exclude "file" field from consistency check (#17651)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: bib(la)tex component: maintable dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) first contrib good first issue An issue intended for project-newcomers. Varies in difficulty. size: small status: changes-required Pull requests that are not yet complete status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Citationcount column sorts alphabetically instead of numerically

4 participants