an error occur when use Document.replaceString
i am writing a plugin. It would insert some words in the active editor.
when i run the command of my plugin , my plugin use Document.replaceString to replace the selected text , it works ,but ,i found an error message , i show it below.
how to handle this? thanks.
(and there is a snapshort about the error message window)
Assertion failed: Write access is allowed inside write-action only (see com.intellij.openapi.application.Application.runWriteAction())
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
at com.intellij.openapi.application.impl.ApplicationImpl.assertWriteAccessAllowed(ApplicationImpl.java:97)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:298)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:42)
at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:85)
at cRText.replaceContent(cRText.java:61)
at cRText.actionPerformed(cRText.java:31)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:6)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:28)
at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:219)
at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:66)
at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:3)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:39)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:135)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:214)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
at com.intellij.openapi.command.impl.DocumentEditingUndoProvider$MyEditorDocumentListener.documentChanged(DocumentEditingUndoProvider.java:39)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.util.EventDispatcher.dispatch(EventDispatcher.java:87)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:33)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:64)
at $Proxy14.documentChanged(Unknown Source)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:213)
at com.intellij.openapi.editor.impl.DocumentImpl.access$100(DocumentImpl.java:199)
at com.intellij.openapi.editor.impl.DocumentImpl$3.afterChangedUpdate(DocumentImpl.java:1)
at com.intellij.openapi.editor.impl.CharArray.replace(CharArray.java:4)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:203)
at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:85)
at cRText.replaceContent(cRText.java:61)
at cRText.actionPerformed(cRText.java:31)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:6)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:28)
at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:219)
at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:66)
at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:3)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:39)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:135)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:214)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
at com.intellij.openapi.command.impl.DocumentEditingUndoProvider$MyEditorDocumentListener.documentChanged(DocumentEditingUndoProvider.java:39)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.util.EventDispatcher.dispatch(EventDispatcher.java:87)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:33)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:64)
at $Proxy14.documentChanged(Unknown Source)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:213)
at com.intellij.openapi.editor.impl.DocumentImpl.access$100(DocumentImpl.java:199)
at com.intellij.openapi.editor.impl.DocumentImpl$3.afterChangedUpdate(DocumentImpl.java:1)
at com.intellij.openapi.editor.impl.CharArray.replace(CharArray.java:4)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:203)
at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:85)
at cRText.replaceContent(cRText.java:61)
at cRText.actionPerformed(cRText.java:31)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:6)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:28)
at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:219)
at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:66)
at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:3)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:39)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:135)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:214)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Attachment(s):
123.jpg
Please sign in to leave a comment.
lingll lingll wrote:
Did you take a look in
com.intellij.openapi.application.Application.runWriteAction() as
suggested in the error message?
N.
i think this is an internal error of the open api,
i just call the Document.replaceString methord , but (i think) then , it will call com.intellij.openapi.application.Application.runWriteAction()
Hello lingll,
No, this is not an internal error of the OpenAPI. Please refer to the following
document:
http://www.jetbrains.net/confluence/display/IDEADEV/IntelliJIDEAArchitectural+Overview
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
thanks , i find the answer.
i call CommandProcessor.executeCommand,and then call application.runWriteAction
but ,it should call twice Runnable, it seems not normal ?
and what is the usage of CommandProcessor.executeCommand , i try to guess how to use it, i call it(see below) by ignore the last 2 parameter.
(public abstract void executeCommand(com.intellij.openapi.project.Project project, java.lang.Runnable runnable, @org.jetbrains.annotations.Nls java.lang.String s, java.lang.Object o);)
Hello lingll,
You can use the WriteCommandAction class if two runnables are inconvenient
for you.
The Plugin Development Package contains the source and javadoc for many of
the OpenAPI classes: http://www.jetbrains.com/idea/plugins/plugin_developers.html
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
thanks , but i have looked up the api document , but can not find more information about CommandProcessor.executeCommand ,
the document just show the declare of it.
and , i worder how to use WriteCommandAction , i can not find more usage information about it from the api document