DisposalException during testing

Hi, i'm writing some tests of my plugin. For those I need to somehow add sources to the project:

val libVFilePointer = VirtualFilePointerManager.getInstance().create("file:///(...)",module,null)
PsiTestUtil.addSourceRoot(module, libVFilePointer.getFile)


The problem is that the exception is thrown. Of course my guess is i need to call .dispose somewhere. Doing so on module causes Already disposed exception. So my next guess is to search for somewhere to register my filepointer, but a glance at the sourcecode discouraged my own explores so I'm asking for help. ;-)

com.intellij.openapi.util.TraceableDisposable$DisposalException: Virtual pointer hasn't been disposed: file:///home/tomaszym/correct/path/to/the/file
--------------Creation trace:
java.lang.Throwable: parent = 'Module: 'light_idea_test_case'' (class com.intellij.openapi.module.impl.ModuleImpl); URL=<null,file:///home/tomaszym/correct/path/to/the/file
at com.intellij.openapi.vfs.impl.VirtualFilePointerImpl.<init>(VirtualFilePointerImpl.java:39)
     at com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl.getOrCreate(VirtualFilePointerManagerImpl.java:256)
     at com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl.create(VirtualFilePointerManagerImpl.java:198)
     at com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl.create(VirtualFilePointerManagerImpl.java:151)
     at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
     at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:108)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at com.intellij.testFramework.UsefulTestCase.access$001(UsefulTestCase.java:80)
     at com.intellij.testFramework.UsefulTestCase$2.run(UsefulTestCase.java:303)
     at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:2070)
     at com.intellij.testFramework.UsefulTestCase.invokeTestRunnable(UsefulTestCase.java:335)
     at com.intellij.testFramework.UsefulTestCase.runTest(UsefulTestCase.java:319)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase.access$001(LightPlatformCodeInsightTestCase.java:70)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase.doRunTest(LightPlatformCodeInsightTestCase.java:110)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase$1$1.run(LightPlatformCodeInsightTestCase.java:88)
     at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:124)
     at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:99)
     at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:85)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase$1.run(LightPlatformCodeInsightTestCase.java:83)
     at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:984)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase.runTest(LightPlatformCodeInsightTestCase.java:98)
     at com.intellij.testFramework.LightPlatformTestCase.startRunAndTear(LightPlatformTestCase.java:695)
     at com.intellij.testFramework.LightPlatformTestCase.access$700(LightPlatformTestCase.java:121)
     at com.intellij.testFramework.LightPlatformTestCase$8.run(LightPlatformTestCase.java:658)
     (at java.awt.....)
-------------Own trace:
com.intellij.openapi.util.TraceableDisposable$DisposalException: Virtual pointer hasn't been disposed: file:///home/tomaszym/correct/path/to/the/file
     at com.intellij.openapi.util.TraceableDisposable.throwDisposalError(TraceableDisposable.java:44)
        at com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl.assertPointersAreDisposed(VirtualFilePointerManagerImpl.java:328)
     at com.intellij.testFramework.LightPlatformTestCase.tearDown(LightPlatformTestCase.java:520)
     at com.intellij.testFramework.LightPlatformCodeInsightTestCase.tearDown(LightPlatformCodeInsightTestCase.java:257)      at org.jetbrains.plugins.scala.base.ScalaLightPlatformCodeInsightTestCaseAdapter.tearDown(ScalaLightPlatformCodeInsightTestCaseAdapter.java:112)
     at com.intellij.testFramework.LightPlatformTestCase.startRunAndTear(LightPlatformTestCase.java:700)
     at com.intellij.testFramework.LightPlatformTestCase.access$700(LightPlatformTestCase.java:121)
     at com.intellij.testFramework.LightPlatformTestCase$8.run(LightPlatformTestCase.java:658)
     (at java.awt.....)

2 comments

The beginning of the stacktrace with already disposed:

java.lang.AssertionError: Already disposed: Module: 'light_idea_test_case'
    at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:186)
    at com.intellij.facet.FacetManager.getInstance(FacetManager.java:31)
    at org.jetbrains.plugins.scala.config.ScalaFacet$.findIn(ScalaFacet.scala:21)
    at org.jetbrains.plugins.scala.base.ScalaLibraryLoader.clean(ScalaLibraryLoader.scala:114)
    at org.jetbrains.plugins.scala.base.ScalaLightPlatformCodeInsightTestCaseAdapter.tearDown(ScalaLightPlatformCodeInsightTestCaseAdapter.java:110)
    at com.intellij.testFramework.LightPlatformTestCase.startRunAndTear(LightPlatformTestCase.java:700)
    at com.intellij.testFramework.LightPlatformTestCase.access$700(LightPlatformTestCase.java:121)
    at com.intellij.testFramework.LightPlatformTestCase$8.run(LightPlatformTestCase.java:658)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
0

That's what I've been missing for a while... hope it will be helpful to someone sometime. ;-)

  protected override def setUp(): Unit = {
    super.setUp()
    (...)
    contentEntry = model.addContentEntry(lib.getParent)
    contentEntry.addSourceFolder(lib, false)

    ApplicationManager.getApplication.runWriteAction(new Runnable {
      def run() {
        model.commit()
      }
    })
  }


  override protected def tearDown(): Unit = {
    (...)
    rootModel.removeContentEntry(contentEntry)
    contentEntry = null

    ApplicationManager.getApplication.runWriteAction(new Runnable {
      def run() {
        rootModel.commit()
      }
    })
    super.tearDown()
  }

0

Please sign in to leave a comment.