StackOverflowError Running Plugin Unit Tests in Ultimate
How do I prevent this StackOverflowError from occurring in my unit tests for my plugin:
java.lang.StackOverflowError
at com.intellij.util.containers.StripedLockConcurrentHashMap$CanonicalHashingStrategy.equals(StripedLockConcurrentHashMap.java:755)
at com.intellij.util.containers._CHMSegment.get(StripedLockConcurrentHashMap.java:888)
at com.intellij.util.containers.StripedLockConcurrentHashMap.get(StripedLockConcurrentHashMap.java:136)
at com.intellij.openapi.editor.markup.AttributesFlyweight.create(AttributesFlyweight.java:100)
at com.intellij.openapi.editor.markup.TextAttributes.setAttributes(TextAttributes.java:173)
at com.intellij.openapi.editor.impl.IterationState.c(IterationState.java:466)
at com.intellij.openapi.editor.impl.IterationState.advance(IterationState.java:251)
at com.intellij.openapi.editor.impl.IterationState.<init>(IterationState.java:150)
at com.intellij.openapi.editor.impl.EditorImpl.xyToVisualPosition(EditorImpl.java:1070)
at com.intellij.openapi.editor.impl.EditorImpl.xyToLogicalPosition(EditorImpl.java:1293)
at com.intellij.codeInsight.daemon.impl.VisibleHighlightingPassFactory.calculateVisibleRange(VisibleHighlightingPassFactory.java:42)
at com.intellij.codeInsight.daemon.impl.ShowAutoImportPass.<init>(ShowAutoImportPass.java:63)
at com.intellij.codeInsight.daemon.impl.ShowAutoImportPassFactory.createHighlightingPass(ShowAutoImportPassFactory.java:56)
at com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPassRegistrarImpl$1.execute(TextEditorHighlightingPassRegistrarImpl.java:128)
at gnu.trove.TIntHash.forEach(TIntHash.java:157)
at gnu.trove.TIntObjectHashMap.forEachKey(TIntObjectHashMap.java:389)
at com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPassRegistrarImpl.instantiatePasses(TextEditorHighlightingPassRegistrarImpl.java:120)
at com.intellij.codeInsight.daemon.impl.TextEditorBackgroundHighlighter.getPasses(TextEditorBackgroundHighlighter.java:95)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:246)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:260)
Here's the file that is my test case.
class Test {
public static void main(String[] args) {
new <warning descr="Unrecommended usage of @Beta annotated construct in Guava framework.">Test</warning>();
}
}
Here's the code from my unit test:
public void testBetaMethodCall() throws Exception {
myFixture.enableInspections(BetaGuavaInspection.class);
myFixture.testHighlighting(true, false, false, "BetaGuavaConstructorCallTest.java");
}
}
public BaseInspectionTestCase() {
System.setProperty(PathManager.PROPERTY_HOME_PATH, "<< IDEA Ultimate Home Path >>");
}
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return new DefaultLightProjectDescriptor() {
@Override
public Sdk getSdk() {
return JavaSdk.getInstance().createJdk("1.7", new File(getSourceRoot(), "mockJDK-1.7").getPath(), false);
}
};
}
protected String getTestDataPath() {
return new File(getSourceRoot(), "[ relative path to test data ]").getPath();
}
private File getSourceRoot() {
return new File(PathManager.getJarPathForClass(BaseInspectionTestCase.class), "../../..");
}
}
请先登录再写评论。
I can download and execute the comparisonChainGen test cases just fine. But, when I run my own, I can't get them to run.
Found it. I needed to add the -ea VM flag to the run configuration. However, now I'm getting the following error.
java.lang.AssertionError: Must not start highlighting from within write action to avoid deadlock
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.runPasses(DaemonCodeAnalyzerImpl.java:231)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.instantiateAndRun(CodeInsightTestFixtureImpl.java:1478)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.doHighlighting(CodeInsightTestFixtureImpl.java:1466)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.a(CodeInsightTestFixtureImpl.java:1424)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.a(CodeInsightTestFixtureImpl.java:1404)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.testHighlighting(CodeInsightTestFixtureImpl.java:335)
at com.vertafore.inspection.BetaGuavaInspectionTest.testBetaMethodCall(BetaGuavaInspectionTest.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.testFramework.UsefulTestCase.access$001(UsefulTestCase.java:69)
at com.intellij.testFramework.UsefulTestCase$2.run(UsefulTestCase.java:244)
at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:1987)
at com.intellij.testFramework.UsefulTestCase.invokeTestRunnable(UsefulTestCase.java:276)
at com.intellij.testFramework.UsefulTestCase.runTest(UsefulTestCase.java:260)
at com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase.access$001(LightPlatformCodeInsightFixtureTestCase.java:39)
at com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase.doRunTests(LightPlatformCodeInsightFixtureTestCase.java:115)
at com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase$1.run(LightPlatformCodeInsightFixtureTestCase.java:103)
at com.intellij.openapi.application.RunResult.run(RunResult.java:37)
at com.intellij.openapi.command.WriteCommandAction$2$1.run(WriteCommandAction.java:126)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1013)
at com.intellij.openapi.command.WriteCommandAction$2.run(WriteCommandAction.java:123)
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.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:120)
at com.intellij.openapi.command.WriteCommandAction.access$000(WriteCommandAction.java:35)
at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:76)
at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:81)
at com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase.runTest(LightPlatformCodeInsightFixtureTestCase.java:100)
at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:281)
at com.intellij.testFramework.UsefulTestCase$3.run(UsefulTestCase.java:293)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Process finished with exit code -1
Hi Brad,
So, the assertion message is rather clear. You can check IJ highlighting tests as a reference, e.g. com.intellij.codeInsight.daemon.LightAdvHighlightingTest
Denis
It also helps to extends the correct test case class: LightCodeInsightFixtureTestCase instead of LightPlatformCodeInsightFixtureTestCase.
I finally got it situated. I was missing some jar files from the classpath for the running test. This was causing some errors after I corrected the parent class issue.
Then I had issues where class I was importing were not found by the test case. I created them in the test data and added them to the test case.
Any referenced source that is in the test data needs to be included in your test. I had to include my "annotation" before my testable source file.