Description
PluginException with TestGenerator.reformat is falling in IDEA when tests are generated.
To Reproduce
Steps to reproduce the behavior:
- Open IntelliJ IDEA
- Plugin is installed
- Create a new IDEA project with JDK 8 (reproduced with Gradle projects and JDK 8/11)
- Add a class like that
public class ListToStringExample {
public void toStringList() {
// Arrays.asList("a", "b", "c").toString();
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.toString();
Random random = new Random();
list.get(random.nextInt(list.size()));
}
public boolean rand(int a) {
Random r = new Random();
return r.nextInt() > a;
}
}
Expected behavior
No exception is supposed to be thrown.
Actual behavior
com.intellij.diagnostic.PluginException is thrown with the following stacktrace:
Visual proofs (screenshots, logs, images)
com.intellij.diagnostic.PluginException: Element: class com.intellij.psi.impl.source.PsiJavaFileImpl #JAVA because: different providers: com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/lWX1182794/UTBotJava/utbot-sample/src/test/java/org/utbot/examples/algorithms/ArraysQuickSortTest.java, vFileId=865906, content=VirtualFileContent{size=77}, eventSystemEnabled=true}(472ad3d4); com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/lWX1182794/UTBotJava/utbot-sample/src/test/java/org/utbot/examples/algorithms/ArraysQuickSortTest.java, vFileId=865906, content=VirtualFileContent{size=77}, eventSystemEnabled=true}(3bd9cfd1)
invalidated at: see attachment [Plugin: com.intellij.java]
at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:23)
at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:92)
at com.intellij.psi.util.PsiUtilCore.ensureValid(PsiUtilCore.java:478)
at com.intellij.psi.impl.DebugUtil.diagnosePsiDocumentInconsistency(DebugUtil.java:564)
at com.intellij.psi.formatter.FormattingDocumentModelImpl.checkDocument(FormattingDocumentModelImpl.java:53)
at com.intellij.psi.formatter.FormattingDocumentModelImpl.createOn(FormattingDocumentModelImpl.java:43)
at com.intellij.lang.java.JavaFormattingModelBuilder.createModel(JavaFormattingModelBuilder.java:41)
at com.intellij.formatting.CoreFormatterUtil.buildModel(CoreFormatterUtil.java:30)
at com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade.processRange(CodeFormatterFacade.java:112)
at com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade.processElement(CodeFormatterFacade.java:67)
at com.intellij.formatting.service.CoreFormattingService.formatElement(CoreFormattingService.java:44)
at com.intellij.formatting.service.FormattingServiceUtil.formatElement(FormattingServiceUtil.java:67)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:82)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformat(CodeStyleManagerImpl.java:65)
at org.utbot.intellij.plugin.generator.TestGenerator.reformat(TestGenerator.kt:308)
at org.utbot.intellij.plugin.generator.TestGenerator.access$reformat(TestGenerator.kt:74)
at org.utbot.intellij.plugin.generator.TestGenerator$addTestMethodsAndSaveReports$1$1$1$2.run(TestGenerator.kt:278)
at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$4(WriteCommandAction.java:362)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:150)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1015)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:148)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:184)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:157)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:124)
at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:362)
at org.utbot.intellij.plugin.generator.TestGenerator$addTestMethodsAndSaveReports$1$1$1.run(TestGenerator.kt:277)
at org.utbot.intellij.plugin.generator.TestGenerator$run$$inlined$let$lambda$3.compute(actions.kt:58)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$runWriteAction$13(ApplicationImpl.java:1024)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:1003)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1024)
at org.utbot.intellij.plugin.generator.TestGenerator.run(TestGenerator.kt:516)
at org.utbot.intellij.plugin.generator.TestGenerator.access$run(TestGenerator.kt:74)
at org.utbot.intellij.plugin.generator.TestGenerator$addTestMethodsAndSaveReports$1$1.run(TestGenerator.kt:263)
at org.utbot.intellij.plugin.generator.TestGenerator$run$$inlined$let$lambda$4.run(ApplicationUtils.kt:59)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:215)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:197)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:511)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:69)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:112)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
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)
Caused by: com.intellij.psi.PsiInvalidElementAccessException: Element: class com.intellij.psi.impl.source.PsiJavaFileImpl #JAVA because: different providers: com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/lWX1182794/UTBotJava/utbot-sample/src/test/java/org/utbot/examples/algorithms/ArraysQuickSortTest.java, vFileId=865906, content=VirtualFileContent{size=77}, eventSystemEnabled=true}(472ad3d4); com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/lWX1182794/UTBotJava/utbot-sample/src/test/java/org/utbot/examples/algorithms/ArraysQuickSortTest.java, vFileId=865906, content=VirtualFileContent{size=77}, eventSystemEnabled=true}(3bd9cfd1)
invalidated at: see attachment
... 64 more
java.lang.Throwable
at com.intellij.psi.impl.DebugUtil.beginPsiModification(DebugUtil.java:446)
at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:479)
at com.intellij.psi.impl.file.impl.FileManagerImpl.setViewProvider(FileManagerImpl.java:244)
at com.intellij.psi.impl.file.impl.FileManagerImpl.forceReload(FileManagerImpl.java:139)
at com.intellij.psi.impl.file.impl.PsiVFSListener.propertyChanged(PsiVFSListener.java:354)
at com.intellij.psi.impl.file.impl.PsiVFSListener.fireForGrouped(PsiVFSListener.java:780)
at one.util.streamex.CollapseSpliterator.accept(CollapseSpliterator.java:152)
at one.util.streamex.CollapseSpliterator.forEachRemaining(CollapseSpliterator.java:142)
at one.util.streamex.AbstractStreamEx.forEach(AbstractStreamEx.java:352)
at com.intellij.psi.impl.file.impl.PsiVFSListener.groupAndFire(PsiVFSListener.java:753)
at com.intellij.psi.impl.file.impl.PsiVFSListener.after(PsiVFSListener.java:742)
at com.intellij.psi.impl.file.impl.PsiVFSListener$1.after(PsiVFSListener.java:147)
at com.intellij.util.messages.impl.MessageBusImpl.invokeMethod(MessageBusImpl.java:642)
at com.intellij.util.messages.impl.MessageBusImpl.invokeListener(MessageBusImpl.java:617)
at com.intellij.util.messages.impl.MessageBusImpl.deliverMessage(MessageBusImpl.java:417)
at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:391)
at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:373)
at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:34)
at com.intellij.util.messages.impl.MessageBusImpl$MessagePublisher.invoke(MessageBusImpl.java:180)
at com.sun.proxy.$Proxy213.after(Unknown Source)
at com.intellij.util.FileContentUtilCore.lambda$reparseFiles$0(FileContentUtilCore.java:49)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1015)
at com.intellij.util.FileContentUtilCore.reparseFiles(FileContentUtilCore.java:37)
at com.intellij.openapi.fileTypes.impl.FileTypeDetectionService.lambda$reparseLater$7(FileTypeDetectionService.java:717)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:215)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:197)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:511)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:69)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:112)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
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)
Environment
Windows 10 Pro
IntelliJ IDEA 2022.1.3
JDK 8, 11
bug