代码之家  ›  专栏  ›  技术社区  ›  yeputons

` nullpointerexception`尝试在从源代码构建的intellij社区上运行no op`lightcodeinsightfixturetestcase`时

  •  1
  • yeputons  · 技术社区  · 6 年前

    我试着创建一个简单的idea插件和一个基于 this 手册:

    package com.example;
    
    import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
    
    public class NoopTest extends LightCodeInsightFixtureTestCase {
        public void testNothing() {
    
        }
    }
    

    然后我创建junit运行配置,让它运行这个类,将工作目录指向 D:\idea-community\bin 目录(见下文)并按照手册设置虚拟机选项:

    -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
    

    然后在调试模式下运行测试,得到以下错误:

    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)
    

    我的设置:

    1. IDEA社区,通过点击“构建-构建项目”在本地构建 Check Out And Build Community Edition “手册”。指向源根的路径类似于 D:\idea-community\ ,所以 D:\idea-community\getPlugins.bat . git commit是 ef98a0ccb
    2. IDEA在调试模式下成功运行。
    3. 这个想法是作为intellij平台插件sdk添加到我的插件项目中的。
    4. 我成功地从我的插件项目运行idea,甚至导航源代码。

    如何修复运行测试时的错误并使其通过?

    1 回复  |  直到 6 年前
        1
  •  1
  •   yeputons    6 年前

    我能通过移除这个问题来解决这个问题。 D:\idea-community\out\production\intellij.pycharm.community\META-INF\PyCharmCorePlugin.xml ,但这感觉像是作弊,因为每次生成时都会重新创建该文件。

    经过进一步调查我发现 PlatformTestCase.doAutodetectPlatformPrefix() 检测 PyCharmCore 而不是 Idea 在这种情况下,看起来像模拟Java SDK(或任何东西)都没有加载,因此 NullPointerException .

    我在JetBrains论坛上发现了一些类似的问题 here (2009) here (2012年起)和 there (2014年起)。测试中的平台自动检测 is a recent thing (2015年起)。而且,它看起来比任何 -Didea.platform.prefix=Idea 我将其作为jvm选项传递,因此我看不到任何更好的解决方案。