Found a leaked instance of class com.intellij.openapi.project.impl.ProjectImpl

Hi,

I’m trying to re-implement my plugin tests using junit5/TestApplication, 2025.2 platform. I have removed all old tests, updated the dependencies and added a single test. The test itself runs but the “test run” complains about the Project not getting disposed:

java.lang.AssertionError: Found a leaked instance of class com.intellij.openapi.project.impl.ProjectImpl
Instance: Project(name=light_temp_35Wa8RMcgSieeFBU70czxitkimA, containerState=disposed temporarily, componentStore=/private/var/folders/8w/jcbd06095qxb0379t1rs9rfr0000gn/T/unitTest__35Wa8OrBgVBCyRedKl3uDYxFpdj/light_temp_35Wa8RMcgSieeFBU70czxitkimA.ipr) (disposed)

.. stripped ...


The instance was created at: Project(name=light_temp_35Wa8RMcgSieeFBU70czxitkimA, containerState=disposed temporarily, componentStore=/private/var/folders/8w/jcbd06095qxb0379t1rs9rfr0000gn/T/unitTest__35Wa8OrBgVBCyRedKl3uDYxFpdj/light_temp_35Wa8RMcgSieeFBU70czxitkimA.ipr) (disposed) 2025-11-15T18:35:27.412761@java.lang.Throwable
at com.intellij.util.ExceptionUtil.currentStackTrace(ExceptionUtil.java:79)
at com.intellij.openapi.project.impl.ProjectImpl.storeCreationTrace(ProjectImpl.kt:410)
at com.intellij.openapi.project.impl.ProjectImpl.setLightProjectName(ProjectImpl.kt:340)
at com.intellij.testFramework.LightPlatformTestCase.doSetup(LightPlatformTestCase.java:275)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:41)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$setUp$42(CodeInsightTestFixtureImpl.java:1377)
at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$3(EdtTestUtil.java:87)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:240)

my test looks like this:

@TestApplication
class FileTypeSpec : LightJavaCodeInsightFixtureTestCase5() {

  override fun getTestDataPath(): String {
    return "src/test/testdata/filetype"
  }

  private fun loadFile(path: String): VirtualFile {
    return fixture.configureByFile(path).virtualFile
  }

  @Test
  fun `detects file type with 'yaml' extension`() {
    val mapping = loadFile("mapping.yaml")
    assertEquals(TypeMappingFileType.NAME, mapping.fileType.name)
  }

} 

I can open the heap dump, I can find the tested class in it… but I don’t really know what to look for. :wink:

Any idea how to make that work? Is this an issue with my plugin? If my plugin should do some clean up, how do I find what/where it is missing?

That message should also print existing strong paths to the leaked instance.

If that path doesn’t contain anything from your plugin, it’s either a bug in the platform or you’re using it in the wrong way. I lack the necessary expertise to tell which is this, but I have one question: do you really need @TestApplication here? I’ve just checked, and it seems LightJavaCodeInsightFixtureTestCase5 initializes an application by itself (at least ApplicationManager.getApplication() returns a non-null value) and there are no leaks if I remove @TestApplication from your example. Maybe that’s the issue?

I also see some LightJavaCodeInsightFixtureTestCase5 tests in our codebase, but none of them uses @TestApplication. I’m not saying it shouldn’t be used, I just don’t know.

after removing @TestApplication it just works…

what is the rule for @TestApplication ? Where can/should I use it?

If I’m not mistaken, LightJavaCodeInsightFixtureTestCase5 is to ease moving from JUnit4 to JUnit5, but it’s not using the annotations also introduced for JUnit5 support.

See intellij-community/platform/testFramework/junit5/test/showcase at master · JetBrains/intellij-community · GitHub how to use annotations and fixtures with JUnit5 without a base class.

Thanks for the tip. :slight_smile:

I tried that first and didn’t get it running. :frowning: Not sure, I think I didn’t find an example that uses test data files and `@TestDataPath` didn’t work for me.

Maybe I try that again…