IncorrectOperationException when trying to modify PsiClass or PsiElement

I developing a plugin to generate customized getters, getters, setters, equals and hash code.
I get an exception when trying to modify the text inside the file, I am using PsiElement PsiClass, adding, deleting stuff etc...

Is there something I am missing? This plugin was used to work since years... and now bum, it stopped working.

This is the exception I get:

Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor: Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor
com.intellij.util.IncorrectOperationException: Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor
 at com.intellij.openapi.editor.impl.DocumentImpl.e(DocumentImpl.java:758)
 at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:731)
 at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:709)
 at com.intellij.openapi.editor.impl.DocumentImpl.deleteString(DocumentImpl.java:519)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:292)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer.access$100(PsiToDocumentSynchronizer.java:37)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer$6.syncDocument(PsiToDocumentSynchronizer.java:264)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer$1.run(PsiToDocumentSynchronizer.java:104)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer.performAtomically(PsiToDocumentSynchronizer.java:128)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer.a(PsiToDocumentSynchronizer.java:101)
 at com.intellij.psi.impl.PsiToDocumentSynchronizer.commitTransaction(PsiToDocumentSynchronizer.java:261)
 at com.intellij.pom.core.impl.PomModelImpl.a(PomModelImpl.java:236)
 at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:195)
 at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:169)
 at com.intellij.psi.impl.source.tree.CompositeElement.a(CompositeElement.java:926)
 at com.intellij.psi.impl.source.tree.CompositeElement.removeRange(CompositeElement.java:681)
 at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChildren(CodeEditUtil.java:173)
 at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChild(CodeEditUtil.java:63)
 at com.intellij.psi.impl.source.tree.CompositeElement.deleteChildInternal(CompositeElement.java:536)
 at com.intellij.psi.impl.source.tree.java.ClassElement.deleteChildInternal(ClassElement.java:224)
 at com.intellij.psi.impl.source.JavaStubPsiElement.delete(JavaStubPsiElement.java:129)
 at Vicosizer$2.run(Vicosizer.java:80)
 at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:984)
 at Vicosizer.vicosize(Vicosizer.java:73)
 at VicosizeClass.actionPerformed(VicosizeClass.java:30)
 at com.intellij.ui.popup.PopupFactoryImpl$ActionPopupStep$1.run(PopupFactoryImpl.java:733)
 at com.intellij.ui.popup.AbstractPopup$18.run(AbstractPopup.java:1248)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.a(FocusManagerImpl.java:651)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.g(FocusManagerImpl.java:632)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.e(FocusManagerImpl.java:602)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.access$200(FocusManagerImpl.java:60)
 at com.intellij.openapi.wm.impl.FocusManagerImpl$IdleRunnable.runEdt(FocusManagerImpl.java:108)
 at com.intellij.openapi.util.EdtRunnable$1.run(EdtRunnable.java:28)
 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
 at java.awt.EventQueue.access$400(EventQueue.java:97)
 at java.awt.EventQueue$3.run(EventQueue.java:697)
 at java.awt.EventQueue$3.run(EventQueue.java:691)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
 at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:697)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:524)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:335)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

2 comments
Comment actions Permalink

Have you tried reading the text of the exception? It tells you exactly what you need to fix the problem.

-1
Comment actions Permalink

Well I was trying to figure out and I thought it was an bug from IntelliJ.
I solved it now using WriteCommandAction

Thanks.

1

Please sign in to leave a comment.