Why throwing AssertionError when removing a listener ?

Working on my plugin i've found that when i try to remove a listener (for example CaretListener) but the listener was not registered, idea throws an AssertionError !
Why not just ignore the fact that the listener was not registered ? I didn't found any way to know if a listener is already registered (without coding it myself)....

4 comments
Comment actions Permalink

Hello Maurice,

MM> Working on my plugin i've found that when i try to remove a listener
MM> (for example CaretListener) but the listener was not registered,
MM> idea throws an AssertionError !
MM>
MM> Why not just ignore the fact that the listener was not registered ?
MM> I didn't found any way to know if a listener is already registered
MM> (without coding it myself)....

Such assertions help us find bugs like duplicate dispose of some components,
so we don't plan to remove them.

Indeed there is no API for finding if a listener is registered, but is your
plugin structure really so complex that you need to add/remove the listener
in many random places?

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Hi Dmitry,

I'm trying to implement AutoScrollFromSource so i've implemented FileEditorManagerListener and CaretListener.

on selectionChanged i'm adding my caretListener to the editor, on fileClosed i'm removing it.

As a workaround i'm using a Map<Editor, CaretListener> to keep trace of registered caretListeners.

Thank you for answering

0
Comment actions Permalink

Hello Maurice,

MM> I'm trying to implement AutoScrollFromSource so i've implemented
MM> FileEditorManagerListener and CaretListener.
MM>
MM> on selectionChanged i'm adding my caretListener to the editor, on
MM> fileClosed i'm removing it.

If you're only interested in caret changes in the active editor, you can
do all processing in selectionChanged - remove the listener from the old
editor and add it to the new editor.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink


I still have the AssertionError on removeCaretListener...

I open a project with few files already opened.
I exit from idea and i've got the exception....

I had the same exception when i tried to add the listerner in fileOpened and removing it in fileClosed but i can't reproduce it so i'll use this option.

0

Please sign in to leave a comment.