Skip to content

Ignore exception in unregisterListener to prevent exception#15761

Merged
Siedlerchr merged 1 commit into
mainfrom
exceptionOnUnregisterListener
May 19, 2026
Merged

Ignore exception in unregisterListener to prevent exception#15761
Siedlerchr merged 1 commit into
mainfrom
exceptionOnUnregisterListener

Conversation

@Siedlerchr

@Siedlerchr Siedlerchr commented May 18, 2026

Copy link
Copy Markdown
Member

Related issues and pull requests

When switching tabs fast I could get this exception after resetting preferences

Fixes https://github.com/JabRef/jabref-issue-melting-pot/issues/1303

PR Description

Steps to test

AI usage


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

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

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Handle exception when unregistering non-registered listeners

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Catch and log IllegalArgumentException in unregisterListener method
• Prevents exception when unregistering non-registered listeners
• Adds logging for debugging listener registration issues
Diagram
flowchart LR
  A["unregisterListener called"] --> B{"Listener registered?"}
  B -->|Yes| C["Unregister successfully"]
  B -->|No| D["Catch IllegalArgumentException"]
  D --> E["Log debug message"]
  E --> F["Continue execution"]
Loading

Grey Divider

File Changes

1. jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java 🐞 Bug fix +8/-1

Add exception handling to unregisterListener method

• Added SLF4J Logger import and static logger instance
• Wrapped eventBus.unregister call in try-catch block
• Catches IllegalArgumentException and logs debug message with listener details
• Prevents application crashes when unregistering listeners that were never registered

jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java


Grey Divider

Qodo Logo

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

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

Copy link
Copy Markdown
Contributor

Code Review by Qodo

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

Context used

Grey Divider


Action required

1. unregisterListener uses exception flow 📘 Rule violation ☼ Reliability
Description
unregisterListener now relies on catching IllegalArgumentException to handle the "not
registered" case, which turns a common state check into exception-driven control flow and can hide
incorrect listener lifecycle management.
Code

jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[R64-69]

    public void unregisterListener(Object listener) {
-        eventBus.unregister(listener);
+        try {
+            eventBus.unregister(listener);
+        } catch (IllegalArgumentException e) {
+            LOGGER.debug("Listener was not registered before: {}", listener, e);
+        }
Evidence
PR Compliance ID 17 forbids using exceptions for regular control flow. The new code catches
IllegalArgumentException to handle an expected "not registered" state during unregisterListener,
rather than preventing the invalid unregister call.

AGENTS.md
jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[64-69]

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

## Issue description
`CoarseChangeFilter.unregisterListener` catches `IllegalArgumentException` from Guava `EventBus.unregister` to handle the "listener was not registered" case. This uses exceptions for non-exceptional control flow and risks masking real listener lifecycle bugs.

## Issue Context
Guava `EventBus` throws `IllegalArgumentException` when unregistering an unknown listener. The code currently treats this as an expected branch.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[64-69]

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



Remediation recommended

2. No tests for unregister change 📘 Rule violation ⚙ Maintainability
Description
The behavior of unregisterListener changed (it no longer propagates IllegalArgumentException),
but the PR does not add or update tests to lock in the new behavior and prevent regressions.
Code

jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[R64-69]

    public void unregisterListener(Object listener) {
-        eventBus.unregister(listener);
+        try {
+            eventBus.unregister(listener);
+        } catch (IllegalArgumentException e) {
+            LOGGER.debug("Listener was not registered before: {}", listener, e);
+        }
Evidence
PR Compliance IDs 20 and 25 require updating/adding tests when logic behavior changes. The diff
changes unregisterListener semantics by catching and ignoring IllegalArgumentException, but no
test changes are included in the PR.

AGENTS.md
AGENTS.md
jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[64-69]

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

## Issue description
`unregisterListener` behavior changed to swallow `IllegalArgumentException`, but there is no corresponding test ensuring that unregistering a non-registered listener does not throw.

## Issue Context
This is a behavior change in `org.jabref.logic` code and should be covered by tests to ensure future refactors do not reintroduce the exception.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[64-69]

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


Grey Divider

Qodo Logo

Comment on lines 64 to +69
public void unregisterListener(Object listener) {
eventBus.unregister(listener);
try {
eventBus.unregister(listener);
} catch (IllegalArgumentException e) {
LOGGER.debug("Listener was not registered before: {}", listener, e);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

1. unregisterlistener uses exception flow 📘 Rule violation ☼ Reliability

unregisterListener now relies on catching IllegalArgumentException to handle the "not
registered" case, which turns a common state check into exception-driven control flow and can hide
incorrect listener lifecycle management.
Agent Prompt
## Issue description
`CoarseChangeFilter.unregisterListener` catches `IllegalArgumentException` from Guava `EventBus.unregister` to handle the "listener was not registered" case. This uses exceptions for non-exceptional control flow and risks masking real listener lifecycle bugs.

## Issue Context
Guava `EventBus` throws `IllegalArgumentException` when unregistering an unknown listener. The code currently treats this as an expected branch.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java[64-69]

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

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.

This is called in the unregister case so it's fine I would say

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.

the original issue was java.lang.IllegalArgumentException: missing event subscriber for an annotated method. Is org.jabref.gui.externalfiles.AutoRenameFileOnEntryChange@fd49e7d registered?

@koppor koppor May 19, 2026

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.

should we add synchronized somewhere maybe?

If the answer is "no" just go ahead and squash-merge to avoid exceptions in main

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be good to also check if this is caused because something is inside runLater although it better should not be

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.

I checked and did not see anything. It's only callsed in library close and is a rare case

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 19, 2026
@Siedlerchr Siedlerchr enabled auto-merge May 19, 2026 21:19
@Siedlerchr Siedlerchr 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 8457ae3 May 19, 2026
151 of 162 checks passed
@Siedlerchr Siedlerchr deleted the exceptionOnUnregisterListener branch May 19, 2026 21:42
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compliance violation 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.

3 participants