LocalQuickFixes and CommandProcessor

I just got an exception when running a quick fix for an error found by my
LocalInspectionTool. I got this exception. Does this mean every intention needs
to be inside executeCommand? Is there some way to automate this (99% of
intentions will want to be undoable and in write action)?

ERROR - pl.DocumentEditingUndoProvider - Assertion failed: Undoable
actions allowed inside commands only (see
com.intellij.openapi.command.CommandProcessor.executeCommand())
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at
com.intellij.openapi.command.impl.DocumentEditingUndoProvider$MyEditorDocumentListener.documentChanged(DocumentEditingUndoProvider.java:30)
at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.util.EventDispatcher.a(EventDispatcher.java:7)
at com.intellij.util.EventDispatcher.a(EventDispatcher.java:68)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:32)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:5)
at $Proxy5.documentChanged(Unknown Source)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:155)
at com.intellij.openapi.editor.impl.DocumentImpl.access$300(DocumentImpl.java:174)
at
com.intellij.openapi.editor.impl.DocumentImpl$3.afterChangedUpdate(DocumentImpl.java)
at com.intellij.openapi.editor.impl.CharArray.insert(CharArray.java:4)
at
com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:114)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:152)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.access$000(PsiToDocumentSynchronizer.java:15)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer$5.syncDocument(PsiToDocumentSynchronizer.java:2)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:3)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.commitTransaction(PsiToDocumentSynchronizer.java:45)
at com.intellij.pom.core.impl.PomModelImpl.a(PomModelImpl.java:36)
at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:131)
at com.intellij.psi.impl.source.xml.XmlTagImpl.a(XmlTagImpl.java:282)
at com.intellij.psi.impl.source.xml.XmlTagImpl.addInternal(XmlTagImpl.java:135)
at
com.intellij.psi.impl.source.tree.CompositePsiElement.addAfter(CompositePsiElement.java:60)
at net.kano.gxpeditor.GxpTools.insertTopElement(GxpTools.java:330)
at net.kano.gxpeditor.GxpTools.addImport(GxpTools.java:436)
at net.kano.gxpeditor.fixes.ShowImportPopupFix$1$1.run(ShowImportPopupFix.java:81)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:349)
at net.kano.gxpeditor.fixes.ShowImportPopupFix$1.run(ShowImportPopupFix.java:78)
at com.intellij.ui.ListPopup.closePopup(ListPopup.java:22)
at com.intellij.ui.ListPopup$3.mouseClicked(ListPopup.java:1)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5565)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5327)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Component.dispatchEventImpl(Component.java:4029)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Component.dispatchEvent(Component.java:3877)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3945)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
at java.awt.Container.dispatchEventImpl(Container.java:2054)
at java.awt.Window.dispatchEventImpl(Window.java:1766)
at java.awt.Component.dispatchEvent(Component.java:3877)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:138)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:162)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:38)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:267)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

4 comments
Comment actions Permalink


It shouldn't be necessary for either LocalQuickFixes or Intentions to manager the CommandProcessor stuff. The framework is already handling all of that. Neither IPP nor IG have do anything like that.

--Dave Griffith

0
Comment actions Permalink

I moved the code inside CommandProcessor, and then inside write action, and now
I get this exception. What's going on? It seems there are lots of problems with
editing XML PSI. Is there some better way to do it, except using tree methods
like addAfter?


java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
at com.intellij.psi.impl.source.tree.ChangeUtil.addChild(ChangeUtil.java:15)
at
com.intellij.psi.impl.source.tree.CompositeElement.addChild(CompositeElement.java:11)
at com.intellij.psi.impl.source.tree.ChangeUtil.addChildren(ChangeUtil.java:24)
at
com.intellij.psi.impl.source.tree.CompositeElement.addChildren(CompositeElement.java:223)
at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.a(CodeEditUtil.java:161)
at
com.intellij.psi.impl.source.codeStyle.CodeEditUtil.addChildren(CodeEditUtil.java:484)
at
com.intellij.psi.impl.source.tree.CompositeElement.addInternal(CompositeElement.java:105)
at com.intellij.psi.impl.source.xml.XmlTagImpl.access$1001(XmlTagImpl.java:80)
at
com.intellij.psi.impl.source.xml.XmlTagImpl$GenericInsertTransaction.runInner(XmlTagImpl.java:8)
at com.intellij.pom.impl.PomTransactionBase.run(PomTransactionBase.java:43)
at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:27)
at com.intellij.psi.impl.source.xml.XmlTagImpl.a(XmlTagImpl.java:282)
at com.intellij.psi.impl.source.xml.XmlTagImpl.addInternal(XmlTagImpl.java:135)
at
com.intellij.psi.impl.source.tree.CompositePsiElement.addAfter(CompositePsiElement.java:60)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.addAfter(OrganizeGxpHeaderAction.java:169)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.organize(OrganizeGxpHeaderAction.java:135)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.access$000(OrganizeGxpHeaderAction.java:58)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction$1$1.run(OrganizeGxpHeaderAction.java:78)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:349)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction$1.run(OrganizeGxpHeaderAction.java:76)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:77)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.actionPerformed(OrganizeGxpHeaderAction.java:74)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:40)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:24)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:173)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:53)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:38)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:267)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at
com.intellij.psi.formatter.FormattingDocumentModelImpl.createOn(FormattingDocumentModelImpl.java:25)
at com.intellij.lang.xml.XMLLanguage$1.createModel(XMLLanguage.java:2)
at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.a(CodeEditUtil.java:467)
at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.a(CodeEditUtil.java:459)
at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.a(CodeEditUtil.java:202)
at
com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChildren(CodeEditUtil.java:392)
at
com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChild(CodeEditUtil.java:473)
at
com.intellij.psi.impl.source.tree.CompositeElement.deleteChildInternal(CompositeElement.java:109)
at com.intellij.psi.impl.source.xml.XmlTagImpl.access$201(XmlTagImpl.java:261)
at
com.intellij.psi.impl.source.xml.XmlTagImpl.deleteChildInternal(XmlTagImpl.java:20)
at
com.intellij.psi.impl.source.tree.CompositePsiElement.delete(CompositePsiElement.java:59)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.organize(OrganizeGxpHeaderAction.java:136)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.access$000(OrganizeGxpHeaderAction.java:58)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction$1$1.run(OrganizeGxpHeaderAction.java:78)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:349)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction$1.run(OrganizeGxpHeaderAction.java:76)
at
com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:77)
at
net.kano.gxpeditor.actions.OrganizeGxpHeaderAction.actionPerformed(OrganizeGxpHeaderAction.java:74)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.a(IdeKeyEventDispatcher.java:40)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.b(IdeKeyEventDispatcher.java:24)
at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:173)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:53)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:38)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:267)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

0
Comment actions Permalink

Hello Keith,

This exception happens because the elements you pass to addAfter() do not
have the same parent.

From what I see, the problems are not with editing the XML PSI, but rather
with insufficient diagnostics in the tree manipulation methods which make
it hard to understand the reason of the programming errors.

KL> I moved the code inside CommandProcessor, and then inside write
KL> action, and now I get this exception. What's going on? It seems
KL> there are lots of problems with editing XML PSI. Is there some
KL> better way to do it, except using tree methods like addAfter?
KL>
KL> java.lang.Throwable
KL> at
KL> com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
KL> at
KL> com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
KL> at
KL> com.intellij.psi.impl.source.tree.ChangeUtil.addChild(ChangeUtil.java:15)

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


0
Comment actions Permalink

The code is now:
assert last.getParent() == parent;
parent.addAfter(copy, last);

And I think I get the same exception.

Dmitry Jemerov (JetBrains) wrote:

Hello Keith,

This exception happens because the elements you pass to addAfter() do
not have the same parent.

From what I see, the problems are not with editing the XML PSI, but
rather with insufficient diagnostics in the tree manipulation methods
which make it hard to understand the reason of the programming errors.

KL> I moved the code inside CommandProcessor, and then inside write
KL> action, and now I get this exception. What's going on? It seems
KL> there are lots of problems with editing XML PSI. Is there some
KL> better way to do it, except using tree methods like addAfter?
KL> KL> java.lang.Throwable
KL> at
KL> com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
KL> at
KL> com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
KL> at
KL>
com.intellij.psi.impl.source.tree.ChangeUtil.addChild(ChangeUtil.java:15)

0

Please sign in to leave a comment.