Skip to content

LO/OO: Refresh citations before syncing bibliography#15352

Merged
subhramit merged 15 commits into
JabRef:mainfrom
subhramit:oo-refresh
Mar 17, 2026
Merged

LO/OO: Refresh citations before syncing bibliography#15352
subhramit merged 15 commits into
JabRef:mainfrom
subhramit:oo-refresh

Conversation

@subhramit

Copy link
Copy Markdown
Member

Closes #14387
Make CSL citations inserted using JabRef LO Converter extension recognizable by "Make/Sync bibliography" out of the box.

image

Convert using JabRef_LibreOffice_Extension to CSL
image

Open JabRef, refresh bibliography
image

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • 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

Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Refresh citations before syncing bibliography in LibreOffice

✨ Enhancement 🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Refresh citations before syncing bibliography in OO/LO panel
• Simplify exception handling by catching generic Exception
• Add test case for LibreOffice extension citation format
• Update changelog with CSL support improvements
Diagram
flowchart LR
  A["Make/Sync Bibliography"] --> B["Refresh Citations"]
  B --> C["Update Citation Styles"]
  C --> D["Mark Manager Updates"]
  D --> E["Generate Bibliography"]
Loading

Grey Divider

File Changes

1. jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java Error handling +2/-8

Simplify exception handling in OO bibliography update

• Removed unused import UnknownPropertyException
• Simplified exception handling by catching generic com.sun.star.uno.Exception instead of multiple
 specific exceptions
• Removed WrappedTargetException from catch block

jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java


2. jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java ✨ Enhancement +5/-2

Refresh citations before inserting bibliography

• Added citation refresh logic before bibliography generation
• Call updateAllCitationsWithNewStyle() to refresh citations
• Set real-time number update requirement and read existing marks
• Changed exception signature from WrappedTargetException to generic Exception

jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java


3. jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java Error handling +3/-5

Simplify exception handling in bibliography rebuild

• Removed unused imports for PropertyVetoException, UnknownPropertyException,
 NoSuchElementException
• Added import for generic com.sun.star.uno.Exception
• Simplified exception signatures in method declarations to use generic Exception

jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java


View more (2)
4. jablib/src/test/java/org/jabref/logic/openoffice/ReferenceMarkTest.java 🧪 Tests +4/-0

Add test for LibreOffice extension citation format

• Added new test case for LibreOffice extension citation format
• Test validates parsing of citation mark with format "JABREF_Keen_2011 CID_100 cite"

jablib/src/test/java/org/jabref/logic/openoffice/ReferenceMarkTest.java


5. CHANGELOG.md 📝 Documentation +2/-0

Document citation refresh and CSL improvements

• Added entry documenting citation refresh feature in OO/LO panel
• Added entry about improved CSL support with LibreOffice converter extension
• Both entries reference issue #14387

CHANGELOG.md


Grey Divider

Qodo Logo

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

qodo-free-for-open-source-projects Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

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

Grey Divider


Action required

1. OOBibBase rethrows RuntimeException📘 Rule violation ⛯ Reliability
Description
The new catch block wraps UNO/document exceptions into an unchecked RuntimeException, which can
crash the update flow and violates the project’s exception-handling standards. It also broadens
exception handling by catching the generic com.sun.star.uno.Exception.
Code

jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[R930-931]

+                } catch (NoDocumentException | com.sun.star.uno.Exception e) {
              throw new RuntimeException(e);
Evidence
PR Compliance requires avoiding unchecked throws and overly broad exception handling. The updated
code now catches a broad UNO exception type and rethrows it as RuntimeException.

AGENTS.md
AGENTS.md
jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[929-932]

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

## Issue description
`OOBibBase.guiActionUpdateDocument` catches a broad `com.sun.star.uno.Exception` and rethrows it as an unchecked `RuntimeException`, which violates the exception-handling compliance rules and risks crashing the UI update flow.
## Issue Context
The PR broadened exception handling in the CSL bibliography update path.
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[929-939]

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


2. CSLUpdateBibliography throws UNO Exception 📘 Rule violation ⛯ Reliability
Description
CSLUpdateBibliography now declares throws com.sun.star.uno.Exception instead of specific UNO
exceptions, reducing precision and making error handling less robust. This conflicts with the
requirement to avoid broad exception types.
Code

jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java[R40-43]

                                 CitationStyle citationStyle,
                                 BibDatabaseContext bibDatabaseContext,
                                 BibEntryTypesManager bibEntryTypesManager)
-            throws WrappedTargetException, NoDocumentException, CreationException, NoSuchElementException, PropertyVetoException, UnknownPropertyException {
+            throws Exception, NoDocumentException, CreationException {
Evidence
The compliance checklist requires specific exception types; the updated method signature now throws
the generic UNO base exception type (com.sun.star.uno.Exception).

AGENTS.md
AGENTS.md
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java[36-44]

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

## Issue description
`CSLUpdateBibliography` now declares `throws com.sun.star.uno.Exception`, which is overly broad and violates the project’s exception specificity rules.
## Issue Context
This PR replaced a list of specific UNO exceptions with the generic UNO base exception.
## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java[36-58]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLUpdateBibliography.java[83-103]

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


3. Refresh marks too late🐞 Bug ✓ Correctness
Description
CSLCitationOOAdapter.insertBibliography calls updateAllCitationsWithNewStyle before
markManager.readAndUpdateExistingMarks, so the citation update runs against stale cached reference
marks and won’t refresh citations created/converted after the adapter was initialized.
Code

jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[R173-183]

public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle, List<BibEntry> entries, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager)
-            throws WrappedTargetException, CreationException {
+            throws Exception, CreationException {
  if (!selectedStyle.hasBibliography()) {
      return;
  }
-
  boolean isNumericStyle = selectedStyle.isNumericStyle();
+        updateAllCitationsWithNewStyle(selectedStyle, false);
+        markManager.setRealTimeNumberUpdateRequired(isNumericStyle);
+        markManager.readAndUpdateExistingMarks();
+
Evidence
insertBibliography updates citations first, but updateAllCitationsWithNewStyle relies on
markManager.getMarksInOrder() and isCitedEntry(); both are based on CSLReferenceMarkManager’s
cached state (marksInOrder/citationKeyToNumber), which is only rebuilt by
readAndUpdateExistingMarks(). Therefore, without reading marks first, newly converted/inserted CSL
reference marks are not considered in the refresh pass.

jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[171-215]
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[264-292]
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java[126-170]
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java[302-309]

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

## Issue description
`insertBibliography` refreshes citation text before refreshing the reference-mark cache, so style refresh runs on stale data and misses citations converted/inserted externally.
### Issue Context
`updateAllCitationsWithNewStyle` uses `markManager.getMarksInOrder()` and `isCitedEntry` (cache-backed). The cache is rebuilt only by `readAndUpdateExistingMarks()`.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[171-215]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[264-360]

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


View more (1)
4. Stale citedEntries filtering🐞 Bug ✓ Correctness
Description
OOBibBase.guiActionUpdateDocument builds citedEntries using cslCitationOOAdapter.isCitedEntry
before any mark refresh, so it can incorrectly return early with “No cited entries found” and never
call bibliography rebuild/refresh.
Code

jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[1]

              doc.lockControllers();
Evidence
The cited-entry detection is cache-based (isCitedEntrymarkManager.hasCitationForKey). If the
document’s marks were changed by external tooling (the exact PR use case), the adapter cache can be
stale until readAndUpdateExistingMarks() runs. Since OOBibBase checks for emptiness and returns
before invoking rebuildCSLBibliography, the new refresh logic in insertBibliography may never
execute.

jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[899-920]
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[362-367]
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java[126-134]

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

## Issue description
The UI code filters cited entries using a cache-backed predicate before any refresh, so it can return early and skip bibliography rebuild.
### Issue Context
`isCitedEntry` depends on `CSLReferenceMarkManager`’s cached `citationKeyToNumber`, rebuilt only by `readAndUpdateExistingMarks()`.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java[899-932]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[54-67]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[362-367]

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


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Signed-off-by: subhramit <subhramit.bb@live.in>
Comment thread jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java Outdated
Signed-off-by: subhramit <subhramit.bb@live.in>
Siedlerchr
Siedlerchr previously approved these changes Mar 16, 2026
@subhramit subhramit changed the title Refresh citations before syncing bibliography LO/OO: Refresh citations before syncing bibliography Mar 16, 2026
@testlens-app

This comment has been minimized.

@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Mar 16, 2026
@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@subhramit subhramit requested a review from Siedlerchr March 16, 2026 23:06
@subhramit subhramit added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Mar 16, 2026
Signed-off-by: subhramit <subhramit.bb@live.in>
@testlens-app

This comment has been minimized.

Signed-off-by: subhramit <subhramit.bb@live.in>
@testlens-app

This comment has been minimized.

Signed-off-by: subhramit <subhramit.bb@live.in>
@testlens-app

This comment has been minimized.

/// The list is generated based on the existing citations, in-text citations and empty citations in the document.
public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle, List<BibEntry> entries, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager)
throws WrappedTargetException, CreationException {
throws Exception, CreationException {

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.

Maybe use qualified name here like in OOBibBase

Image

to avoid confusion with java.lang.Exception

also in CSLUpdateBibliography

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good idea

Signed-off-by: subhramit <subhramit.bb@live.in>
@testlens-app

This comment has been minimized.

Comment thread jabgui/src/main/java/org/jabref/gui/openoffice/OOBibBase.java
@subhramit subhramit requested a review from calixtus March 17, 2026 09:45
@testlens-app

testlens-app Bot commented Mar 17, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 8ae559d
▶️ Tests: 10187 executed
⚪️ Checks: 52/52 completed


Learn more about TestLens at testlens.app.

@subhramit subhramit added this pull request to the merge queue Mar 17, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label Mar 17, 2026
Merged via the queue into JabRef:main with commit 885927e Mar 17, 2026
52 checks passed
@subhramit subhramit deleted the oo-refresh branch March 17, 2026 21:36
AnvitaPrasad pushed a commit to AnvitaPrasad/jabref that referenced this pull request Mar 18, 2026
* Refresh citations before syncing bibliography

Signed-off-by: subhramit <subhramit.bb@live.in>

* Add test

Signed-off-by: subhramit <subhramit.bb@live.in>

* Add comment to testcase

Signed-off-by: subhramit <subhramit.bb@live.in>

* Changelog

Signed-off-by: subhramit <subhramit.bb@live.in>

* Restore gap

Signed-off-by: subhramit <subhramit.bb@live.in>

* Better exception handling

Signed-off-by: subhramit <subhramit.bb@live.in>

* Take qodo suggestion

Signed-off-by: subhramit <subhramit.bb@live.in>

* l10n

Signed-off-by: subhramit <subhramit.bb@live.in>

* Change order of real time number update

Signed-off-by: subhramit <subhramit.bb@live.in>

* Change order of real time number update

Signed-off-by: subhramit <subhramit.bb@live.in>

* Better exception handling, use qualified names

Signed-off-by: subhramit <subhramit.bb@live.in>

---------

Signed-off-by: subhramit <subhramit.bb@live.in>
Siedlerchr added a commit that referenced this pull request Mar 18, 2026
* upstream/main:
  Chore(deps): Bump jablib/src/main/resources/csl-styles (#15365)
  Chore(deps): Bump styfle/cancel-workflow-action from 0.13.0 to 0.13.1 (#15364)
  Update dependency com.ibm.icu:icu4j to v78.3 (#15361)
  LO/OO: Refresh citations before syncing bibliography (#15352)
FynnianB pushed a commit to FynnianB/jabref that referenced this pull request Mar 19, 2026
* Refresh citations before syncing bibliography

Signed-off-by: subhramit <subhramit.bb@live.in>

* Add test

Signed-off-by: subhramit <subhramit.bb@live.in>

* Add comment to testcase

Signed-off-by: subhramit <subhramit.bb@live.in>

* Changelog

Signed-off-by: subhramit <subhramit.bb@live.in>

* Restore gap

Signed-off-by: subhramit <subhramit.bb@live.in>

* Better exception handling

Signed-off-by: subhramit <subhramit.bb@live.in>

* Take qodo suggestion

Signed-off-by: subhramit <subhramit.bb@live.in>

* l10n

Signed-off-by: subhramit <subhramit.bb@live.in>

* Change order of real time number update

Signed-off-by: subhramit <subhramit.bb@live.in>

* Change order of real time number update

Signed-off-by: subhramit <subhramit.bb@live.in>

* Better exception handling, use qualified names

Signed-off-by: subhramit <subhramit.bb@live.in>

---------

Signed-off-by: subhramit <subhramit.bb@live.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: libre-office status: no-bot-comments status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers 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.

Version 6.0 no longer works with JabRef_LibreOffice_Converter

4 participants