Assertion when removing DocumentListener

In my i18n plugin which I mentioned in an earlier post, I use a
DocumentListener to discover when a properties file has been changed so
that I may reload the properties into the associated model object that
is used internally by my plugin.

However, I don't want to be notified when plugin-initiated changes via
the model object are causing the changes in the underlying Document. So,
I remove the DocumentListener, update the Document and then add the
DocumentListener again. The model object doesn't retain a reference to
the Document, it uses FileDocumentManager.getDocument() every time it
needs to read or update the document.

The problem is that I'm seeing the following assertion error when
removing the listener in my UpdateBundleFile Runnable which is executed
Application.runWriteAction(). Unfortunately, the assertion doesn't give
any information what the actual problem is.

Can somebody shed some light on this?

Assertion failed
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:77)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:85)
at
com.intellij.openapi.editor.impl.DocumentImpl.removeDocumentListener(DocumentImpl.java:163)
at
com.quest.ideaplugins.i18nplugin.model.LogResourceBundle$UpdateBundleFile.run(LogResourceBundle.java:623)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:139)
at
com.quest.ideaplugins.i18nplugin.model.LogResourceBundle.updateBundleFile(LogResourceBundle.java:400)
at
com.quest.ideaplugins.i18nplugin.model.LogResourceBundle.deleteResource(LogResourceBundle.java:320)
at
com.quest.ideaplugins.i18nplugin.model.CatListTableModel$DeleteResourceCommand.run(CatListTableModel.java:417)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:109)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:20)
at com.quest.ideaplugins.Utils.executeCommand(Utils.java:97)
at
com.quest.ideaplugins.i18nplugin.model.CatListTableModel.removeItem(CatListTableModel.java:209)
at
com.quest.ideaplugins.i18nplugin.actions.DeleteResourceAction.actionPerformed(DeleteResourceAction.java:54)
at
com.quest.ideaplugins.i18nplugin.actions.CatListAction.actionPerformed(CatListAction.java:69)
at
com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:46)
at
com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:20)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:25)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:46)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:62)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

3 comments

bump

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0

I'll hazard a guess that the listener you're trying to remove isn't registered with the
document, thus causing the assertion. Wouldn't it be easier to have some active/inactive
flag in your listener than adding/removing it on every plugin-initiated edit?

Sascha

0

Sascha Weinreuter wrote:

I'll hazard a guess that the listener you're trying to remove isn't
registered with the document, thus causing the assertion. Wouldn't it be
easier to have some active/inactive flag in your listener than
adding/removing it on every plugin-initiated edit?


I suppose, but I'd really like to know my listener is no longer
registered. Is it perhaps a different Document object? Or is something
else removing listeners from the Document? Either seem utterly bizarre.

I have a similar problem when trying to remove two other listeners:
CaretListener on an Editor's CaretModel and VisibleAreaListener on an
Editor's ScrollingModel.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0

Please sign in to leave a comment.