Incorrect Operation Exception

Good Afternoon, 

Starting from today I got an Error regarding Incorrect Operation Exception: 

Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor

I used the write command action 

WriteCommandAction.runWriteCommandAction(myProject, () -> {applicationTag.addSubTag(activityTag, true);});
WriteCommandAction.runWriteCommandAction(myProject, () -> {applicationTag.addSubTag(redActivityTag, false);});
CodeStyleManager.getInstance(manifestFile.getProject()).reformat(manifestFile);

so, I don't understand what is the reason for the aforementioned error.  

 

Thank you in advance

7 comments
Official comment

What's the full stack trace of the error?

Yes, Of course. 

 

com.intellij.util.IncorrectOperationException: Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor
at com.intellij.pom.core.impl.PomModelImpl.startTransaction(PomModelImpl.java:348)
at com.intellij.pom.core.impl.PomModelImpl.lambda$runTransaction$2(PomModelImpl.java:141)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:185)
at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:140)
at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:155)
at com.intellij.psi.impl.source.tree.CompositeElement.removeChildrenInner(CompositeElement.java:831)
at com.intellij.psi.impl.source.tree.CompositeElement.removeChildInner(CompositeElement.java:825)
at com.intellij.psi.impl.source.tree.CompositeElement.removeChild(CompositeElement.java:640)
at com.intellij.psi.formatter.FormatterUtil.replaceWhiteSpace(FormatterUtil.java:355)
at com.intellij.lang.xml.XmlFormattingModel.replaceWithPsiInLeaf(XmlFormattingModel.java:87)
at com.intellij.psi.formatter.PsiBasedFormattingModel.replaceWithPSI(PsiBasedFormattingModel.java:101)
at com.intellij.psi.formatter.PsiBasedFormattingModel.replaceWhiteSpace(PsiBasedFormattingModel.java:64)
at com.intellij.formatting.engine.FormatProcessorUtils.replaceWhiteSpace(FormatProcessorUtils.java:45)
at com.intellij.formatting.engine.ApplyChangesState.doIteration(ApplyChangesState.java:175)
at com.intellij.formatting.engine.State.iteration(State.java:25)
at com.intellij.formatting.engine.StateProcessor.iteration(StateProcessor.java:41)
at com.intellij.formatting.FormatProcessor.iteration(FormatProcessor.java:107)
at com.intellij.formatting.FormatterImpl$MyFormattingTask.iteration(FormatterImpl.java:926)
at com.intellij.formatting.FormatterImpl.execute(FormatterImpl.java:330)
at com.intellij.formatting.FormatterImpl.format(FormatterImpl.java:295)
at com.intellij.formatting.FormatterImpl.format(FormatterImpl.java:273)
at com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade.doProcessRange(CodeFormatterFacade.java:131)
at com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade.processRange(CodeFormatterFacade.java:95)
at com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade.processElement(CodeFormatterFacade.java:91)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:87)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:71)
at eu.fbk.STAnD.GenerateAction.inspectAndroidManifest(GenerateAction.java:159)
at eu.fbk.STAnD.GenerateAction.generateSupportiveClasses(GenerateAction.java:90)
at eu.fbk.STAnD.GenerateAction.actionPerformed(GenerateAction.java:59)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:220)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:237)
at com.intellij.ui.popup.ActionPopupStep.performAction(ActionPopupStep.java:203)
at com.intellij.ui.popup.ActionPopupStep.performAction(ActionPopupStep.java:191)
at com.intellij.ui.popup.ActionPopupStep.lambda$onChosen$2(ActionPopupStep.java:185)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195)
at com.intellij.ui.popup.AbstractPopup.lambda$dispose$8(AbstractPopup.java:1409)
at com.intellij.util.ui.UIUtil.invokeLaterIfNeeded(UIUtil.java:3097)
at com.intellij.ide.IdeEventQueue.ifFocusEventsInTheQueue(IdeEventQueue.java:176)
at com.intellij.ide.IdeEventQueue.executeWhenAllFocusEventsLeftTheQueue(IdeEventQueue.java:132)
at com.intellij.openapi.wm.impl.FocusManagerImpl.doWhenFocusSettlesDown(FocusManagerImpl.java:190)
at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.doWhenFocusSettlesDown(IdeFocusManagerImpl.java:58)
at com.intellij.ui.popup.AbstractPopup.dispose(AbstractPopup.java:1403)
at com.intellij.ui.popup.WizardPopup.dispose(WizardPopup.java:160)
at com.intellij.ui.popup.list.ListPopupImpl.dispose(ListPopupImpl.java:307)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.dispose(PopupFactoryImpl.java:289)
at com.intellij.openapi.util.Disposer$1.execute(Disposer.java:48)
at com.intellij.openapi.util.Disposer$1.execute(Disposer.java:44)
at com.intellij.openapi.util.objectTree.ObjectNode$1.execute(ObjectNode.java:138)
at com.intellij.openapi.util.objectTree.ObjectNode$1.execute(ObjectNode.java:107)
at com.intellij.openapi.util.objectTree.ObjectTree.executeActionWithRecursiveGuard(ObjectTree.java:182)
at com.intellij.openapi.util.objectTree.ObjectNode.execute(ObjectNode.java:107)
at com.intellij.openapi.util.objectTree.ObjectTree.executeAll(ObjectTree.java:151)
at com.intellij.openapi.util.Disposer.dispose(Disposer.java:129)
at com.intellij.openapi.util.Disposer.dispose(Disposer.java:125)
at com.intellij.ui.popup.WizardPopup.disposeAllParents(WizardPopup.java:263)
at com.intellij.ui.popup.list.ListPopupImpl.handleNextStep(ListPopupImpl.java:442)
at com.intellij.ui.popup.list.ListPopupImpl._handleSelect(ListPopupImpl.java:396)
at com.intellij.ui.popup.list.ListPopupImpl.handleSelect(ListPopupImpl.java:342)
at com.intellij.ui.popup.PopupFactoryImpl$ActionGroupPopup.handleSelect(PopupFactoryImpl.java:309)
at com.intellij.ui.popup.list.ListPopupImpl$MyMouseListener.mouseReleased(ListPopupImpl.java:501)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at com.intellij.ui.popup.list.ListPopupImpl$MyList.processMouseEvent(ListPopupImpl.java:552)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:781)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:718)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
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)

0

It raises this exception, but complete all of the works that are supposed to do. 

0

There's no command or WriteCommandAction in this trace, hence the error. It should be somewhere around here:

at eu.fbk.STAnD.GenerateAction.inspectAndroidManifest(GenerateAction.java:159)
at eu.fbk.STAnD.GenerateAction.generateSupportiveClasses(GenerateAction.java:90)
at eu.fbk.STAnD.GenerateAction.actionPerformed(GenerateAction.java:59)

0
public void actionPerformed(AnActionEvent e) {
PsiClass psiclass = getPsiClassFromContext(e);
insertCodeHandler = new InsertCodeHandler(psiclass);
myProject = psiclass.getProject();
e.getPresentation().setEnabled(psiclass != null);
GenerateDialog dlg = new GenerateDialog (psiclass);
dlg.show();
if (!GenerateClass.INSTANCE.isHasTest() & !GenerateClass.INSTANCE.isHasRedirect()){
if (dlg.isOK()) {
Messages.showErrorDialog("Please complete the needed information ", "No Items Selected");
}
}
else {
if (dlg.isOK()) {
dlg.doValidate();
generateComparable(psiclass);
insertCodeHandler.invoke(myProject);
generateSupportiveClasses();
inspectBuildGradle();
}
}
}
private void generateSupportiveClasses() {
String glideTemplate = "AppAuthGlideModuleTemplate.java";
String configTemplate = "ConfigurationTemplate.java";
String connectionTemplate = "ConnectionBuilderForTestingTemplate.java";
String authStateManagerTemplate = "AuthStateManagerClassTemplate.java";
String oidchWithRefTokentemplate = "TokenActivityOIDCWithRefTokenTemplate.java";
JavaDirectoryService.getInstance().createClass(psiDirectory, "AppAuthGlideModule", glideTemplate, true);
JavaDirectoryService.getInstance().createClass(psiDirectory, GenerateClass.INSTANCE.getClassNameAuth(), authStateManagerTemplate, true);
JavaDirectoryService.getInstance().createClass(psiDirectory, GenerateClass.INSTANCE.getClassNameConfiguration(),configTemplate , true);
JavaDirectoryService.getInstance().createClass(psiDirectory, GenerateClass.INSTANCE.getClassNameConnectionBuilderForTesting(), connectionTemplate, true);

if (GenerateClass.INSTANCE.isHasTest()){
JavaDirectoryService.getInstance().createClass(psiDirectory, GenerateClass.INSTANCE.getClassNameTokenOAuth(),oidchWithRefTokentemplate , true);
generateUserInterfaceFile();
inspectAndroidManifest();
}
}
private void inspectAndroidManifest() {

Module[] modules = ModuleManager.getInstance(ProjectManager.getInstance().getOpenProjects()[0]).getSortedModules();
Module module = modules[modules.length-2];
AndroidFacet facet=AndroidFacet.getInstance(module);
Manifest manifest = facet.getManifest();
if (manifest==null){
return;
}

if (activityTag != null & redActivityTag!=null & GenerateClass.INSTANCE.isHasTest()) {
WriteCommandAction.runWriteCommandAction(myProject, () -> {applicationTag.addSubTag(activityTag, true);});
WriteCommandAction.runWriteCommandAction(myProject, () -> {applicationTag.addSubTag(redActivityTag, false);});
CodeStyleManager.getInstance(manifestFile.getProject()).reformat(manifestFile);
}
if (activityTag != null & redActivityTag!=null & !GenerateClass.INSTANCE.isHasTest()) {
WriteCommandAction.runWriteCommandAction(myProject, () -> {applicationTag.addSubTag(redActivityTag, false);});
CodeStyleManager.getInstance(manifestFile.getProject()).reformat(manifestFile);
}
}
0

I provide you with the code of the aforementioned classes if you have some suggestion I will appreciate it. 

0

I'd wrap the whole generation into a single (write)command.

0

Please sign in to leave a comment.