Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Outdated stub in index" and "PSI and index do not match." #43

Open
bitspittle opened this issue Mar 27, 2024 · 5 comments
Open

"Outdated stub in index" and "PSI and index do not match." #43

bitspittle opened this issue Mar 27, 2024 · 5 comments
Assignees
Milestone

Comments

@bitspittle
Copy link
Contributor

Outdated stub in index

Outdated stub in index: file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/KotlinRenderer.kt, vFileId=766123, indexing timestamp = 1711577686385, binary = false, byte size = 19029, char size = 19029, doc=DocumentImpl[file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/KotlinRenderer.kt], docSaved=true, wasIndexedAlready=true, queried at 1711577686385
doc length=19427
file length=19427
cached PSI class org.jetbrains.kotlin.psi.KtFile
PSI length=19427
projects with file: 1
physical file exists; length = 19427

java.lang.Exception
	at com.intellij.psi.stubs.StubTreeLoaderImpl.diagnoseLengthMismatch(StubTreeLoaderImpl.java:188)
	at com.intellij.psi.stubs.StubTreeLoaderImpl.checkLengthMatch(StubTreeLoaderImpl.java:152)
	at com.intellij.psi.stubs.StubTreeLoaderImpl.readFromVFile(StubTreeLoaderImpl.java:119)
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.doCreateCompleteException(StubTreeLoader.java:184)
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.lambda$createCompleteException$0(StubTreeLoader.java:178)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
	at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.createCompleteException(StubTreeLoader.java:177)
	at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:227)
	at com.intellij.psi.impl.source.PsiFileImpl.calcTreeElement(PsiFileImpl.java:733)
	at com.intellij.extapi.psi.StubBasedPsiElementBase.getNode(StubBasedPsiElementBase.java:126)
	at com.intellij.extapi.psi.ASTDelegatePsiElement.getText(ASTDelegatePsiElement.java:133)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.isKobwebColorFunction(KobwebColorProvider.kt:188)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.tryParseKobwebColorFunctionCall(KobwebColorProvider.kt:110)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:84)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:93)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor$default(KobwebColorProvider.kt:63)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProvider.getColorFrom(KobwebColorProvider.kt:48)
	at com.intellij.ui.ColorLineMarkerProvider.lambda$collectSlowLineMarkers$0(ColorLineMarkerProvider.java:47)
	at com.intellij.openapi.extensions.ExtensionPointName.computeSafeIfAny(ExtensionPointName.kt:70)
	at com.intellij.ui.ColorLineMarkerProvider.collectSlowLineMarkers(ColorLineMarkerProvider.java:46)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.queryProviders(LineMarkersPass.java:226)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.lambda$doCollectMarkers$2(LineMarkersPass.java:108)
	at com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Divider.java:98)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectMarkers(LineMarkersPass.java:104)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectInformation(LineMarkersPass.java:77)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:55)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:418)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:109)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:34)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:413)
	at com.intellij.openapi.application.impl.RwLockHolder.tryRunReadAction(RwLockHolder.kt:310)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:958)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$4(PassExecutorService.java:404)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:403)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:379)
	at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:795)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$1(PassExecutorService.java:379)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:199)
	at com.intellij.openapi.application.impl.RwLockHolder.executeByImpatientReader(RwLockHolder.kt:491)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:377)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:190)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)```

PSI and index do not match

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: PSI and index do not match.
Please report the problem to JetBrains with the files attached
 file=KtFile: MarkdownBlock.kt, file.class=class org.jetbrains.kotlin.psi.KtFile, file.lang=Language: kotlin, modStamp=1
 tree consistent
 stub debugInfo=created in getStubTree(), with AST = false; with backReference
 viewProvider=com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/MarkdownBlock.kt, vFileId=763947, content=VirtualFileContent{size=6019}, eventSystemEnabled=true}
 viewProvider stamp: 1179455; file stamp: 1179455; file modCount: 1711578271400; file length: 6019
 doc saved: true; doc stamp: 1179455; doc size: 6019; committed: true
indexing info: indexing timestamp = 1711578271400, binary = false, byte size = 6671, char size = 6671
ref: 50cf572587cf
latestIndexedStub=null
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.doCreateCompleteException(StubTreeLoader.java:203)
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.lambda$createCompleteException$0(StubTreeLoader.java:178)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
	at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
	at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.createCompleteException(StubTreeLoader.java:177)
	at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:227)
	at com.intellij.psi.impl.source.PsiFileImpl.calcTreeElement(PsiFileImpl.java:733)
	at com.intellij.extapi.psi.StubBasedPsiElementBase.getNode(StubBasedPsiElementBase.java:126)
	at com.intellij.extapi.psi.ASTDelegatePsiElement.getText(ASTDelegatePsiElement.java:133)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.isKobwebColorFunction(KobwebColorProvider.kt:188)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.tryParseKobwebColorFunctionCall(KobwebColorProvider.kt:110)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:84)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:93)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor$default(KobwebColorProvider.kt:63)
	at com.varabyte.kobweb.intellij.colors.KobwebColorProvider.getColorFrom(KobwebColorProvider.kt:48)
	at com.intellij.ui.ColorLineMarkerProvider.lambda$collectSlowLineMarkers$0(ColorLineMarkerProvider.java:47)
	at com.intellij.openapi.extensions.ExtensionPointName.computeSafeIfAny(ExtensionPointName.kt:70)
	at com.intellij.ui.ColorLineMarkerProvider.collectSlowLineMarkers(ColorLineMarkerProvider.java:46)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.queryProviders(LineMarkersPass.java:226)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.lambda$doCollectMarkers$2(LineMarkersPass.java:108)
	at com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Divider.java:98)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectMarkers(LineMarkersPass.java:104)
	at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectInformation(LineMarkersPass.java:77)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:55)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:418)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:109)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:34)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:413)
	at com.intellij.openapi.application.impl.RwLockHolder.tryRunReadAction(RwLockHolder.kt:310)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:958)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$4(PassExecutorService.java:404)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:403)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:379)
	at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:795)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$1(PassExecutorService.java:379)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:199)
	at com.intellij.openapi.application.impl.RwLockHolder.executeByImpatientReader(RwLockHolder.kt:491)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:377)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:190)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.AssertionError: Stub count doesn't match stubbed node length
	at com.intellij.psi.impl.source.FileTrees.lambda$reconcilePsi$4(FileTrees.java:182)
	at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:548)
	at com.intellij.psi.impl.source.FileTrees.reconcilePsi(FileTrees.java:175)
	at com.intellij.psi.impl.source.FileTrees.withAst(FileTrees.java:141)
	at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:213)
	... 44 more
@bitspittle bitspittle self-assigned this Mar 27, 2024
@bitspittle bitspittle added this to the Next release milestone Mar 27, 2024
@bitspittle
Copy link
Contributor Author

I'll be honest, I'm not really sure what's going on here.

The color provider extension point is just doing some checks using PSI elements passed in from the IJ framework. There's no caching.

I don't think the fundamental issue (outdated stubs, etc.) is something I'm causing. Possibly I can wrap my code in a try / catch Throwable to avoid getting pointed at as a bad extension by IDEA.

@Nxllpointer
Copy link
Collaborator

Nxllpointer commented Mar 28, 2024

@bitspittle Wrapping the entire parsing function in a try-catch seems a little overkill. From what I can deduce using the stacktrace, stuff goes downhill when accessing this.valueParameterList?.text inside of isKobwebColorFunction. Maybe there is some safe version of fetching the text? Regardless i would rather catch errors inside of isKobwebColorFunction. Also you can use runCatching { ... }.getOrDefault(false) for a nicer way of ignoring errors here.

@Nxllpointer
Copy link
Collaborator

I do aggree though that this is probably not the plugin causing the issue

@bitspittle
Copy link
Contributor Author

bitspittle commented Mar 28, 2024

Thanks @Nxllpointer for also taking a look.

It's possible the best course of action is to actually remove the code I introduced entirely. This seems like such a fundamental error that there's no way we could catch all places.

It's also unfortunately very timing specific and hard (impossible?) for us to reproduce.

Here are some more interesting links that LoP surfaced:

LoP saw the error two times when they were doing rebase / merges.

@Nxllpointer
Copy link
Collaborator

Could this perhaps be due to a race condition? I am pretty certain our getColorFrom gets called on some other thread, so the PSI tree could possibly be updated while our method is running. That might explain why the error surfaced when rebasing/merging, since a lot of code gets changed in an instant by an external source. Very wild speculation though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants