Search code examples
intellij-ideaintellij-plugin

`NullPointerException` when trying to run no-op `LightCodeInsightFixtureTestCase` on IntelliJ Community built from source


I've tried to create a simple IDEA plugin and a test case for it based on this manual:

package com.example;

import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;

public class NoopTest extends LightCodeInsightFixtureTestCase {
    public void testNothing() {

    }
}

Then I create JUnit run configuration, make it run this class, point working directory to D:\idea-community\bin directory (see below) and set VM options as per the manual:

-ea -Xbootclasspath/p:../out/classes/production/boot -XX:+HeapDumpOnOutOfMemoryError -Xmx512m -XX:MaxPermSize=320m -Didea.system.path=../test-system -Didea.home.path=../ -Didea.config.path=../test-config -Didea.test.group=ALL_EXCLUDE_DEFINED

Then I run the test in debug mode and get the following error:

CompositeException (2 nested):
------------------------------
[0]: java.lang.NullPointerException
    at com.intellij.testFramework.IdeaTestUtil.createMockJdk(IdeaTestUtil.java:77)
    at com.intellij.testFramework.IdeaTestUtil.getMockJdk(IdeaTestUtil.java:72)
    at com.intellij.testFramework.IdeaTestUtil.getMockJdk17(IdeaTestUtil.java:85)
    at com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase$1.getSdk(LightCodeInsightFixtureTestCase.java:60)
    at com.intellij.testFramework.LightProjectDescriptor.lambda$createContentEntry$3(LightProjectDescriptor.java:135)
    at com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel(ModuleRootModificationUtil.java:143)
    at com.intellij.testFramework.LightProjectDescriptor.createContentEntry(LightProjectDescriptor.java:134)
    at com.intellij.testFramework.LightProjectDescriptor.lambda$setUpProject$0(LightProjectDescriptor.java:58)
    at com.intellij.openapi.application.WriteAction.run(WriteAction.java:105)
    at com.intellij.testFramework.LightProjectDescriptor.setUpProject(LightProjectDescriptor.java:52)
    at com.intellij.testFramework.LightPlatformTestCase.initProject(LightPlatformTestCase.java:242)
    at com.intellij.testFramework.LightPlatformTestCase.doSetup(LightPlatformTestCase.java:303)
    at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:37)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$setUp$24(CodeInsightTestFixtureImpl.java:1190)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:14)
    at com.intellij.testFramework.EdtTestUtilKt.runInEdtAndWait(EdtTestUtil.kt:55)
    at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.kt)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(CodeInsightTestFixtureImpl.java:1189)
    at com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase.setUp(LightCodeInsightFixtureTestCase.java:76)
    at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:358)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:14)
    at com.intellij.testFramework.EdtTestUtilKt$runInEdtAndWait$2.run(EdtTestUtil.kt:59)
    at java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:301)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
    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.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:361)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    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)

[1]: java.lang.AssertionError: setUp() has not been called
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at com.intellij.testFramework.fixtures.impl.BaseFixture.tearDown(BaseFixture.java:48)
    at com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl.tearDown(LightTempDirTestFixtureImpl.java:64)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$null$32(CodeInsightTestFixtureImpl.java:1241)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:14)
    at com.intellij.testFramework.EdtTestUtilKt.runInEdtAndWait(EdtTestUtil.kt:37)
    at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.kt)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$tearDown$33(CodeInsightTestFixtureImpl.java:1241)
    at com.intellij.testFramework.RunAll.collectExceptions(RunAll.java:60)
    at com.intellij.testFramework.RunAll.run(RunAll.java:52)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.tearDown(CodeInsightTestFixtureImpl.java:1247)
    at com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase.tearDown(LightCodeInsightFixtureTestCase.java:88)
    at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:370)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:19)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:14)
    at com.intellij.testFramework.EdtTestUtilKt$runInEdtAndWait$2.run(EdtTestUtil.kt:59)
    at java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:301)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
    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.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:361)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    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)

My set-up:

  1. IDEA Community, built locally by clicking "Build - Build project" after following the "Check Out And Build Community Edition" manual. Path to the source root is something like D:\idea-community\, so that there is D:\idea-community\getPlugins.bat. Git commit is ef98a0ccb.
  2. IDEA successfully runs in debug mode.
  3. This IDEA is added as an IntelliJ Platform Plugin SDK to my plugin project.
  4. I successfully run IDEA from my plugin project, and even navigate the source code.

How do I fix the error when running the test and make it pass?


Solution

  • I was able to fix the problem by removing D:\idea-community\out\production\intellij.pycharm.community\META-INF\PyCharmCorePlugin.xml, but that feels like a cheat because that file gets recreated with every build.

    After further investigation I found out that PlatformTestCase.doAutodetectPlatformPrefix() detects PyCharmCore instead of Idea and it looks like mock Java SDK (or whatever) is not loaded in that case, hence NullPointerException.

    I've found some mentions of similar problems on JetBrains forums here (from 2009), here (from 2012) and there (from 2014). It looks like platform autodetection in tests is a recent thing (from 2015). Moreover, it looks like it overrides any -Didea.platform.prefix=Idea that I pass as JVM options, so I don't see any better solution.