Why do I get java.lang.IllegalArgumentException when I call setUp from LightPlatformCodeInsightTestCase
I want to test my KotlinParser. It extends the class KotlinRecursiveElementWalkingVisitor. So in order to test the class I have to create a mock PsiFile. I tried to use the LightPlatformCodeInsightTestCase class which provides the createLightFile method. So I implemented the following test class:import com.intellij.testFramework.LightPlatformCodeInsightTestCaseimport org.apache.commons.io.IOUtilsimport org.junit.jupiter.api.Testimport java.io.Fileimport java.io.FileInputStreamclass PluginCeckerTest : LightPlatformCodeInsightTestCase() { @Test fun checkTestBuildFile1_kotlin() { super.setUp() val parser = KotlinParser() val testFile = File("src/test/resources/test_build_scripts/testbuild1.gradle.kts") val filecontent = IOUtils.toString( FileInputStream(testFile), "UTF-8") val psifile = createLightFile("test.gradle.kts", filecontent) if (psifile != null) { parser.visitFile(psifile) } }}
I already checked with println that the code fails during super.setUp().
This is the error that I get:
java.lang.IllegalArgumentException: Argument for @NotNull parameter 's' of com/intellij/openapi/util/text/StringUtil.trimStart must not be null at com.intellij.openapi.util.text.StringUtil.$$$reportNull$$$0(StringUtil.java) at com.intellij.openapi.util.text.StringUtil.trimStart(StringUtil.java) at com.intellij.testFramework.LightPlatformTestCase.getTestName(LightPlatformTestCase.java:552) at com.intellij.testFramework.UsefulTestCase.createGlobalTempDirectory(UsefulTestCase.java:254) at com.intellij.testFramework.UsefulTestCase.setupTempDir(UsefulTestCase.java:242) at com.intellij.testFramework.UsefulTestCase.setUp(UsefulTestCase.java:214) at com.intellij.testFramework.LightPlatformTestCase.lambda$setUp$2(LightPlatformTestCase.java:222) at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$1(EdtTestUtil.java:40) at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209) at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21) at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831) at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:456) at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:101) at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:79) at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122) at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:788) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:731) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:758) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:667) at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$7(IdeEventQueue.kt:571) at com.intellij.openapi.application.impl.ApplicationImpl.withoutImplicitRead(ApplicationImpl.java:1446) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:571) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:995) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:995) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385) 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)
I don't know how to resolve this error. In case you need further information I will be happy to provide it.
Thanks in advance for your help!
请先登录再写评论。
Hi Niko,
It seems that you use JUnit 3 and 4 compatible base class (see
com.intellij.testFramework.UsefulTestCase) and try to run it with JUnit 5. The context cannot be initialized properly, hence the NPE.I suggest switching to an older JUnit version. As far as I know, JUnit 5 support is not mature enough yet.