JetBrains / MPS-extensions

MPS-extensions aims to ease language development within MPS.
https://jetbrains.github.io/MPS-extensions/
Apache License 2.0
83 stars 52 forks source link

Custom Project View: runRebuildAction failes with NullPointerException #901

Closed arimer closed 3 months ago

arimer commented 4 months ago

In MPS 2022.2 this exceptions appears frequently:


java.lang.NullPointerException: Cannot invoke "jetbrains.mps.ide.ui.tree.MPSTree.runRebuildAction(java.lang.Runnable, boolean)" because the return value of "jetbrains.mps.ide.ui.tree.MPSTreeNode.getTree()" is null
    at jetbrains.mps.ide.ui.tree.MPSTreeNode.updateSubTree(MPSTreeNode.java:201)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater.updateChildren(CustomTreeNodesUpdater.java:119)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater$3.visit(CustomTreeNodesUpdater.java:111)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater$3.visit(CustomTreeNodesUpdater.java:109)
    at jetbrains.mps.internal.collections.runtime.IVisitor.invoke(IVisitor.java:12)
    at jetbrains.mps.internal.collections.runtime.IterableUtils.visitAll(IterableUtils.java:16)
    at jetbrains.mps.internal.collections.runtime.AbstractSequence.visitAll(AbstractSequence.java:80)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater.updateChildrens(CustomTreeNodesUpdater.java:109)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater.doUpdate(CustomTreeNodesUpdater.java:79)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater.lambda$update$0(CustomTreeNodesUpdater.java:57)
    at jetbrains.mps.smodel.WorkbenchModelAccess.runReadAction(WorkbenchModelAccess.java:80)
    at jetbrains.mps.smodel.ModelAccessBase.runReadAction(ModelAccessBase.java:56)
    at jetbrains.mps.smodel.ModelReadRunnable.run(ModelReadRunnable.java:46)
    at jetbrains.mps.ide.ThreadUtils$LogExceptionsRunnable.run(ThreadUtils.java:80)
    at jetbrains.mps.ide.ThreadUtils.runInUIThreadNoWait(ThreadUtils.java:57)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater.update(CustomTreeNodesUpdater.java:57)
    at com.mbeddr.mpsutil.projectview.runtime.tree.CustomTreeNodesUpdater$1.eventsHappened(CustomTreeNodesUpdater.java:35)
    at com.mbeddr.mpsutil.projectview.runtime.tree.GlobalModelsEventsCollector$1.commandFinished(GlobalModelsEventsCollector.java:34)
    at jetbrains.mps.extapi.module.SRepositoryEventsDispatcher.fireCommandFinished(SRepositoryEventsDispatcher.java:119)
    at jetbrains.mps.extapi.module.SRepositoryBase.fireCommandFinished(SRepositoryBase.java:122)
    at jetbrains.mps.smodel.MPSModuleRepository.access$100(MPSModuleRepository.java:54)
    at jetbrains.mps.smodel.MPSModuleRepository$1.commandFinished(MPSModuleRepository.java:105)
    at java.base/java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:807)
    at jetbrains.mps.smodel.ActionDispatcher.onExit(ActionDispatcher.java:222)
    at jetbrains.mps.smodel.ActionDispatcher.dispatch(ActionDispatcher.java:114)
    at jetbrains.mps.smodel.ActionDispatcher.lambda$wrap$0(ActionDispatcher.java:135)
    at jetbrains.mps.smodel.ActionDispatcher.dispatch(ActionDispatcher.java:98)
    at jetbrains.mps.smodel.ActionDispatcher.lambda$wrap$0(ActionDispatcher.java:135)
    at jetbrains.mps.smodel.LockRunnable.run(LockRunnable.java:60)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1023)
    at jetbrains.mps.smodel.TryRunPlatformWriteHelper.runWrite(TryRunPlatformWriteHelper.java:103)
    at jetbrains.mps.smodel.TryRunPlatformWriteHelper.lambda$withPlatformWrite$1(TryRunPlatformWriteHelper.java:96)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:164)
    at jetbrains.mps.smodel.WorkbenchModelAccess.executeCommand(WorkbenchModelAccess.java:302)
    at jetbrains.mps.smodel.ProjectModelAccess2.executeCommand(ProjectModelAccess2.java:35)
    at jetbrains.mps.nodeEditor.actions.CellActionExecuter.lambda$execute$2(CellActionExecuter.java:57)
    at jetbrains.mps.nodeEditor.EditorContext.lambda$runWithContextCell$3(EditorContext.java:253)
    at jetbrains.mps.nodeEditor.EditorContext.runWithContextCell(EditorContext.java:264)
    at jetbrains.mps.nodeEditor.EditorContext.runWithContextCell(EditorContext.java:252)
    at jetbrains.mps.nodeEditor.actions.CellActionExecuter.execute(CellActionExecuter.java:53)
    at jetbrains.mps.nodeEditor.actions.ActionHandlerImpl.executeAction(ActionHandlerImpl.java:41)
    at jetbrains.mps.nodeEditor.selection.EditorCellSelection.executeAction(EditorCellSelection.java:169)
    at jetbrains.mps.nodeEditor.selection.EditorCellLabelSelection.performDeleteAction(EditorCellLabelSelection.java:199)
    at jetbrains.mps.nodeEditor.selection.EditorCellLabelSelection.executeAction(EditorCellLabelSelection.java:164)
    at jetbrains.mps.ide.editor.actions.Delete_Action.doExecute(Delete_Action.java:58)
    at jetbrains.mps.workbench.action.BaseAction.lambda$actionPerformed$2(BaseAction.java:208)
    at jetbrains.mps.workbench.action.ActionAccess$EmptyAccess.runWithAccess(ActionAccess.java:58)
    at jetbrains.mps.workbench.action.BaseAction.actionPerformed(BaseAction.java:200)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:315)
    at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:47)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:595)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$9(IdeKeyEventDispatcher.java:717)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$10(IdeKeyEventDispatcher.java:717)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:337)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.doPerformActionInner(IdeKeyEventDispatcher.java:714)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:658)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:606)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:489)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:478)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:229)
    at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:824)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:760)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:450)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:449)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113)
    at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:624)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:447)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:493)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)```
arimer commented 3 months ago

Steps to reproduce the issue inside the mps-extensions project:

  1. build the LogicalViewClone
  2. Switch from the logical view to the the LogicalViewClone (Only direct after the swtich the error appears)
  3. Create a model inside a solution
  4. Create a root node (ex. BaseLanauge Class) inside the newly created model
arimer commented 3 months ago

What I've seen so far during debugging is that:

arimer commented 3 months ago

Conclusion:

It looks like old treeNodes that do not longer belong to any tree but were still in the list of treenodes for update. Adding a condition to filter out those no longer required nodes works bests here.