What's this exception?

Hello, I want to know what means an exception. It happens during this
(abbreviated) code:

public static void insertItemIntoList(Project project,
PsiElement expression,
PsiElement lastArg,
PsiElement element)
throws IncorrectOperationException {
ASTNode add = element.getNode().copyElement();
if (lastArg == null) {
...

} else {
ASTNode lastArgNode = lastArg.getNode();
ASTNode comma = createComma(project);
ASTNode parent = lastArgNode.getTreeParent();
ASTNode afterLast = lastArgNode.getTreeNext();
if (afterLast == null) {
parent.addChild(add);
} else {
parent.addChild(add, afterLast); // exception here
}
parent.addChild(comma, add);
}
}

Does anything look wrong with this code?

java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at
com.intellij.openapi.command.impl.DocumentEditingUndoProvider$MyEditorDocumentListener.documentChanged(DocumentEditingUndoProvider.java:29)
at sun.reflect.GeneratedMethodAccessor38.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:23)
at com.intellij.util.EventDispatcher.a(EventDispatcher.java:33)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:34)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:1)
at $Proxy5.documentChanged(Unknown Source)
at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:111)
at
com.intellij.openapi.editor.impl.DocumentImpl.access$300(DocumentImpl.java:230)
at
com.intellij.openapi.editor.impl.DocumentImpl$3.afterChangedUpdate(DocumentImpl.java:3)
at com.intellij.openapi.editor.impl.CharArray.insert(CharArray.java:45)
at
com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:195)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:130)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.access$000(PsiToDocumentSynchronizer.java:148)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer$5.syncDocument(PsiToDocumentSynchronizer.java)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:27)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.commitTransaction(PsiToDocumentSynchronizer.java:74)
at com.intellij.pom.core.impl.PomModelImpl.a(PomModelImpl.java:104)
at
com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:110)
at com.intellij.psi.impl.source.tree.ChangeUtil.a(ChangeUtil.java:315)
at
com.intellij.psi.impl.source.tree.ChangeUtil.addChild(ChangeUtil.java:132)
at
com.intellij.psi.impl.source.tree.CompositeElement.addChild(CompositeElement.java:181)
at
ru.yole.pythonid.psi.PyChangeUtil.insertItemIntoList(PyChangeUtil.java:171)
at
ru.yole.pythonid.psi.impl.PyListLiteralExpressionImpl.addExpression(PyListLiteralExpressionImpl.java:40)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToExpression(XmlBasedBuildRule.java:133)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToExpression(XmlBasedBuildRule.java:142)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToArgument(XmlBasedBuildRule.java:125)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addSource(XmlBasedBuildRule.java:82)
at
com.google.devtools.buildeditor.intellij.ChooseBuildFileDialog$AddAction$1.run(ChooseBuildFileDialog.java:169)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:166)
at
com.google.devtools.buildeditor.intellij.ChooseBuildFileDialog$AddAction.actionPerformed(ChooseBuildFileDialog.java:166)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
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:13)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:131)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:28)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
at java.awt.Dialog$1.run(Dialog.java:515)
at java.awt.Dialog.show(Dialog.java:536)
at java.awt.Component.show(Component.java:1300)
at java.awt.Component.setVisible(Component.java:1253)
at
com.google.devtools.buildeditor.intellij.BuildFileManagerImpl$1$1.run(BuildFileManagerImpl.java:183)
at
com.intellij.openapi.application.impl.LaterInvocatorEx$FlushQueue.run(LaterInvocatorEx.java:18)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:13)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:101)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:28)
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)

1 comment

Hello Keith,

Assertion seem to have message for the case: Undoable actions allowed inside
commands only...
That means you're changing PSI and those changes are applied to the underlying
document and the user should be able to undo them.
Breifly, your code should run inside runnable under CommandProcessor.executeCommand

-


Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hello, I want to know what means an exception. It happens during this
(abbreviated) code:

public static void insertItemIntoList(Project project,
PsiElement expression,
PsiElement lastArg,
PsiElement element)
throws IncorrectOperationException {
ASTNode add = element.getNode().copyElement();
if (lastArg == null) {
...
} else {
ASTNode lastArgNode = lastArg.getNode();
ASTNode comma = createComma(project);
ASTNode parent = lastArgNode.getTreeParent();
ASTNode afterLast = lastArgNode.getTreeNext();
if (afterLast == null) {
parent.addChild(add);
} else {
parent.addChild(add, afterLast); // exception here
}
parent.addChild(comma, add);
}
}
Does anything look wrong with this code?

java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at
com.intellij.openapi.command.impl.DocumentEditingUndoProvider$MyEditor
DocumentListener.documentChanged(DocumentEditingUndoProvider.java:29)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.util.EventDispatcher.a(EventDispatcher.java:23)
at com.intellij.util.EventDispatcher.a(EventDispatcher.java:33)
at
com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:34)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:1)
at $Proxy5.documentChanged(Unknown Source)
at
com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:111)
at
com.intellij.openapi.editor.impl.DocumentImpl.access$300(DocumentImpl.
java:230)
at
com.intellij.openapi.editor.impl.DocumentImpl$3.afterChangedUpdate(Doc
umentImpl.java:3)
at
com.intellij.openapi.editor.impl.CharArray.insert(CharArray.java:45)
at
com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImp
l.java:195)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchro
nizer.java:130)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.access$000(PsiToDocume
ntSynchronizer.java:148)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer$5.syncDocument(PsiToDo
cumentSynchronizer.java)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchro
nizer.java:27)
at
com.intellij.psi.impl.PsiToDocumentSynchronizer.commitTransaction(PsiT
oDocumentSynchronizer.java:74)
at com.intellij.pom.core.impl.PomModelImpl.a(PomModelImpl.java:104)
at
com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.ja
va:110)
at
com.intellij.psi.impl.source.tree.ChangeUtil.a(ChangeUtil.java:315)
at
com.intellij.psi.impl.source.tree.ChangeUtil.addChild(ChangeUtil.java:
132)
at
com.intellij.psi.impl.source.tree.CompositeElement.addChild(CompositeE
lement.java:181)
at
ru.yole.pythonid.psi.PyChangeUtil.insertItemIntoList(PyChangeUtil.java
:171)
at
ru.yole.pythonid.psi.impl.PyListLiteralExpressionImpl.addExpression(Py
ListLiteralExpressionImpl.java:40)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToEx
pression(XmlBasedBuildRule.java:133)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToEx
pression(XmlBasedBuildRule.java:142)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addLineToAr
gument(XmlBasedBuildRule.java:125)
at
com.google.devtools.buildeditor.intellij.XmlBasedBuildRule.addSource(X
mlBasedBuildRule.java:82)
at
com.google.devtools.buildeditor.intellij.ChooseBuildFileDialog$AddActi
on$1.run(ChooseBuildFileDialog.java:169)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(A
pplicationImpl.java:166)
at
com.google.devtools.buildeditor.intellij.ChooseBuildFileDialog$AddActi
on.actionPerformed(ChooseBuildFileDialog.java:166)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:184
9)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java
:2169)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.
java:420)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonLi
stener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
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
:13)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:131)
at
com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:28)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThr
ead.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThrea
d.java:163)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThrea
d.java:153)
at java.awt.Dialog$1.run(Dialog.java:515)
at java.awt.Dialog.show(Dialog.java:536)
at java.awt.Component.show(Component.java:1300)
at java.awt.Component.setVisible(Component.java:1253)
at
com.google.devtools.buildeditor.intellij.BuildFileManagerImpl$1$1.run(
BuildFileManagerImpl.java:183)
at
com.intellij.openapi.application.impl.LaterInvocatorEx$FlushQueue.run(
LaterInvocatorEx.java:18)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java
:13)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:101)
at
com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:28)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThr
ead.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThrea
d.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)



0

Please sign in to leave a comment.