Ignore exception in unregisterListener to prevent exception#15761
Conversation
Review Summary by QodoHandle exception when unregistering non-registered listeners
WalkthroughsDescription• Catch and log IllegalArgumentException in unregisterListener method • Prevents exception when unregistering non-registered listeners • Adds logging for debugging listener registration issues Diagramflowchart 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"]
File Changes1. jablib/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java
|
Code Review by Qodo
Context used 1. unregisterListener uses exception flow
|
| public void unregisterListener(Object listener) { | ||
| eventBus.unregister(listener); | ||
| try { | ||
| eventBus.unregister(listener); | ||
| } catch (IllegalArgumentException e) { | ||
| LOGGER.debug("Listener was not registered before: {}", listener, e); | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
This is called in the unregister case so it's fine I would say
There was a problem hiding this comment.
the original issue was java.lang.IllegalArgumentException: missing event subscriber for an annotated method. Is org.jabref.gui.externalfiles.AutoRenameFileOnEntryChange@fd49e7d registered?
There was a problem hiding this comment.
should we add synchronized somewhere maybe?
If the answer is "no" just go ahead and squash-merge to avoid exceptions in main
There was a problem hiding this comment.
Might be good to also check if this is caused because something is inside runLater although it better should not be
There was a problem hiding this comment.
I checked and did not see anything. It's only callsed in library close and is a rare case
* 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)
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
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)