Skip to content

Fix wrong usage of "key"#15779

Merged
koppor merged 2 commits into
mainfrom
fix-key
May 19, 2026
Merged

Fix wrong usage of "key"#15779
koppor merged 2 commits into
mainfrom
fix-key

Conversation

@koppor

@koppor koppor commented May 19, 2026

Copy link
Copy Markdown
Member

OMG, we used org.jabref.model.entry.field.StandardField#KEY.

I think, mostly not user-facing; but still...

Steps to test

Some strang Endnote export

AI usage

Just for the initial refacotring.

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 a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
  • [/] I described the change in CHANGELOG.md in a way that can be understood by the average user (if 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

@koppor koppor added the dev: code-quality Issues related to code or architecture decisions label May 19, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix incorrect usage of StandardField.KEY for citation keys

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Replace incorrect StandardField.KEY usage with InternalField.KEY_FIELD for citation keys
• StandardField.KEY is a BibTeX sorting field, not the citation key identifier
• Update field mappings in exporters and integrity checkers to use correct field type
• Add clarifying documentation distinguishing sorting key from citation key
Diagram
flowchart LR
  A["StandardField.KEY<br/>Sorting field only"] -->|"Incorrect usage"| B["Citation key operations"]
  C["InternalField.KEY_FIELD<br/>Citation key identifier"] -->|"Correct replacement"| B
  B --> D["Fixed in exporters,<br/>integrity checks,<br/>and tests"]
Loading

Grey Divider

File Changes

1. jabgui/src/test/java/org/jabref/gui/commonfxcontrols/SaveOrderPanelViewModelTest.java 🐞 Bug fix +2/-1

Replace StandardField.KEY with InternalField.KEY_FIELD

jabgui/src/test/java/org/jabref/gui/commonfxcontrols/SaveOrderPanelViewModelTest.java


2. jablib/src/main/java/org/jabref/logic/exporter/EndnoteXmlExporter.java 🐞 Bug fix +2/-1

Fix Endnote exporter field mapping for citation key

jablib/src/main/java/org/jabref/logic/exporter/EndnoteXmlExporter.java


3. jablib/src/main/java/org/jabref/logic/integrity/CitationKeyDuplicationChecker.java 🐞 Bug fix +2/-2

Use correct field type for citation key duplication check

jablib/src/main/java/org/jabref/logic/integrity/CitationKeyDuplicationChecker.java


View more (6)
4. jablib/src/main/java/org/jabref/logic/integrity/FieldCheckers.java 🐞 Bug fix +6/-5

Reorganize field checkers and fix citation key validation

jablib/src/main/java/org/jabref/logic/integrity/FieldCheckers.java


5. jablib/src/main/java/org/jabref/logic/msbib/MSBibMapping.java 📝 Documentation +2/-0

Add clarifying comment about StandardField.KEY usage

jablib/src/main/java/org/jabref/logic/msbib/MSBibMapping.java


6. jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java 📝 Documentation +1/-1

Add TODO comment and remove unnecessary assertion

jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java


7. jablib/src/main/java/org/jabref/model/entry/BibEntry.java 🐞 Bug fix +1/-0

Exclude StandardField.KEY from field conversion

jablib/src/main/java/org/jabref/model/entry/BibEntry.java


8. jablib/src/main/java/org/jabref/model/entry/field/StandardField.java 📝 Documentation +8/-0

Add documentation clarifying KEY vs SORTKEY distinction

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


9. jablib/src/test/java/org/jabref/logic/integrity/CitationKeyDuplicationCheckerTest.java 🧪 Tests +1/-1

Update test to use correct citation key field type

jablib/src/test/java/org/jabref/logic/integrity/CitationKeyDuplicationCheckerTest.java


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Crossref KEY inheritance broken ✓ Resolved 🐞 Bug ≡ Correctness
Description
BibEntry#getSourceField now treats StandardField.KEY as a forbidden field, so
BibEntry#getResolvedFieldOrAlias(StandardField.KEY, db) will no longer inherit "key" from the
crossref parent. This contradicts the existing CrossrefTest expectations that StandardField.KEY is
inherited via same-name inheritance, likely breaking crossref resolution behavior and tests.
Code

jablib/src/main/java/org/jabref/model/entry/BibEntry.java[R192-197]

              (targetField == StandardField.XREF) ||
              (targetField == StandardField.ENTRYSET) ||
              (targetField == StandardField.RELATED) ||
+                (targetField == StandardField.KEY) ||
              (targetField == StandardField.SORTKEY)) {
          return Optional.empty();
Evidence
The PR change explicitly forbids StandardField.KEY in crossref source-field mapping, while
CrossrefTest includes StandardField.KEY in the "sameNameInheritance" cases, asserting it should be
inherited from parent to child.

jablib/src/main/java/org/jabref/model/entry/BibEntry.java[188-198]
jablib/src/test/java/org/jabref/model/entry/CrossrefTest.java[212-223]
jablib/src/test/java/org/jabref/model/entry/CrossrefTest.java[276-279]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`BibEntry#getSourceField` was changed to return `Optional.empty()` for `StandardField.KEY`. This disables crossref inheritance for the BibTeX `key` field.
The repo’s crossref tests indicate `StandardField.KEY` is expected to be inherited (same-name inheritance). With the new forbidden check, resolving `KEY` via `getResolvedFieldOrAlias(..., db)` will return empty, causing behavior change and likely test failures.
### Issue Context
- `InternalField.KEY_FIELD` is the citation key; `StandardField.KEY` is a normal BibTeX field (used for sorting in some styles). Even if it’s “rare”, the codebase currently expects it to participate in crossref inheritance.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/model/entry/BibEntry.java[188-198]
### Suggested fix
Remove `StandardField.KEY` from the forbidden-fields list in `getSourceField` (or, if the intended behavior is to stop inheriting it, update the crossref behavior/tests accordingly and document the breaking change).

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


Grey Divider

Qodo Logo

@Siedlerchr

Copy link
Copy Markdown
Member
    EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.KEY, StandardField.SORTKEY);

(targetField == StandardField.XREF) ||
(targetField == StandardField.ENTRYSET) ||
(targetField == StandardField.RELATED) ||
(targetField == StandardField.KEY) ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that added?

Siedlerchr
Siedlerchr previously approved these changes May 19, 2026
@koppor koppor added this pull request to the merge queue May 19, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label May 19, 2026
Merged via the queue into main with commit c96ab6b May 19, 2026
57 checks passed
@koppor koppor deleted the fix-key branch May 19, 2026 21:36
Siedlerchr added a commit that referenced this pull request May 20, 2026
* upstream/main:
  Update PULL_REQUEST_TEMPLATE.md (#15788)
  New Crowdin updates (#15787)
  Update heylogs to 0.18.0 and use github-actions format (#15786)
  Grand refactoring of the AI features (#15688)
  Chore(deps): Bump com.fasterxml:aalto-xml in /versions (#15782)
  Chore(deps): Bump org.junit:junit-bom from 6.0.3 to 6.1.0 in /versions (#15783)
  Fix default value for unwanted characters (#15743)
  Fix runner tag
  Fix runner for JBang (PR)
  Fix duplicate finder progress counter incrementing on empty queue polls (#15781)
  Refine JabKit CLI: positional input argument and check command group (#15759)
  Ignore exception in unregisterListener to prevent exception (#15761)
  Fix wrong usage of "key" (#15779)
  Fix Hayagriva export to nest identifiers under serial-number (#15750)
f0restron07 pushed a commit to f0restron07/jabref that referenced this pull request May 24, 2026
* Fix wrong usage of "key" (used for sorting at bibtex tool, NOT the citation key)

* Revert change in BibEntry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev: code-quality Issues related to code or architecture decisions 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.

2 participants