fix: guard isTestoFile against invalid VirtualFile#52
Merged
Conversation
TestoIconProvider could trigger an "Outdated stub in index" exception when invoked on a stale PsiFile whose underlying physical file no longer existed (e.g. a deleted vendor/autoload.php still cached in the stub index). isTestoFile() walked the AST via PsiTreeUtil before any validity check, forcing AST load and crashing on the stub mismatch. Short-circuit isTestoFile() if the file is not a PhpFile, has no VirtualFile, or its VirtualFile is no longer valid - avoiding any PSI traversal in those cases.
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2026.1.0
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
The original report showed an "Outdated stub in index" exception triggered by isTestoFile() called on a stale PsiFile from vendor/ - where the physical file was already deleted but the VFS hadn't refreshed yet, so virtualFile.isValid still returned true. A bare isValid check is therefore not enough. To make isTestoFile() robust: - Skip files outside project content (ProjectFileIndex.isInContent), excluded folders and IDE-ignored paths - this filters out vendor/ and similar locations before any PSI traversal happens, removing the root cause for the reported case. - Wrap the AST-loading traversal in a try/catch that rethrows ProcessCanceledException and downgrades any other Throwable (including StubTreeAndIndexUnmatchCoarseException) to a logged warning + false, so a transient index inconsistency can no longer propagate as an unhandled exception through callers (live templates, inspection suppressor, run config producer, etc.).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TestoIconProvider could trigger an "Outdated stub in index" exception when invoked on a stale PsiFile whose underlying physical file no longer existed (e.g. a deleted vendor/autoload.php still cached in the stub index). isTestoFile() walked the AST via PsiTreeUtil before any validity check, forcing AST load and crashing on the stub mismatch.
Short-circuit isTestoFile() if the file is not a PhpFile, has no VirtualFile, or its VirtualFile is no longer valid - avoiding any PSI traversal in those cases.