redhat-developer / redhat-developer/lsp4ij

PsiInvalidElementAccessException when clicking on stale element in Find view

Open
#147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
344
Forks
113
Avg merge
5h 22m
Merged PRs (30d)
15

Description

I haven't managed to reproduce it, but basically, after finding usages of an element, if you delete the reference in the code, then matching reference in the Find view becomes stale and I ended up with this exception:

com.intellij.psi.PsiInvalidElementAccessException: Element: class com.intellij.psi.impl.source.PsiPlainTextFileImpl #TEXT  because: different providers: com.intellij.psi.SingleRootFileViewProvider{vFile=file:///Users/fbricon/Dev/projects/lemminx/foo/src/main/typescript/index.ts, vFileId=311, content=VirtualFileContent{size=239}, eventSystemEnabled=true}(79c9e275); com.intellij.psi.SingleRootFileViewProvider{vFile=file:///Users/fbricon/Dev/projects/lemminx/foo/src/main/typescript/index.ts, vFileId=311, content=VirtualFileContent{size=239}, eventSystemEnabled=true}(3df47da6)
invalidated at: see attachment; Element class com.redhat.devtools.lsp4ij.usages.LSPUsagePsiElement(Language: ANY) claims to be valid but returns invalid containing file
	at com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl.ensureValid(SmartPointerManagerImpl.java:114)
	at com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl.createSmartPsiElementPointer(SmartPointerManagerImpl.java:82)
	at com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl.createSmartPsiElementPointer(SmartPointerManagerImpl.java:75)
	at com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl.createSmartPsiElementPointer(SmartPointerManagerImpl.java:70)
	at com.intellij.psi.impl.ElementBase$ElementIconRequest.<init>(ElementBase.java:164)
	at com.intellij.psi.impl.ElementBase$ElementIconRequest.<init>(ElementBase.java:159)
	at com.intellij.psi.impl.ElementBase.computeIcon(ElementBase.java:80)
	at com.intellij.psi.impl.ElementBase.getIcon(ElementBase.java:60)
	at com.intellij.psi.impl.FakePsiElement.getIcon(FakePsiElement.java:121)
	at com.intellij.usages.UsageInfo2UsageAdapter.computeIcon(UsageInfo2UsageAdapter.java:555)
	at com.intellij.usages.UsageInfo2UsageAdapter.doUpdateCachedPresentation(UsageInfo2UsageAdapter.java:484)
	at com.intellij.usages.UsageInfo2UsageAdapter.updateCachedPresentation(UsageInfo2UsageAdapter.java:476)
	at com.intellij.usages.impl.UsageNode.updateCachedPresentation(UsageNode.java:74)
	at com.intellij.usages.impl.Node.update(Node.java:98)
	at com.intellij.usages.impl.UsageViewImpl.lambda$queueUpdateBulk$37(UsageViewImpl.java:1522)

I believe the problem is LSPPsiElement.isValid() always returns true.

When deleting a java reference for instance, the usage should show as INVALID
Screenshot 2024-02-20 at 10 03 50

When the exception isn't thrown, I see the element in the find view is just updated to a blank line or the code replacing the deleted reference.

https://github.com/redhat-developer/lsp4ij/assets/148698/da6439b6-751c-41e4-a0c3-d472ba314ba0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting LSPPsiElement.isValid() and reproduce the stale-reference flow in the IntelliJ Find view after deleting a matched code reference. Confirm that the usage is marked invalid instead of causing PsiInvalidElementAccessException or displaying replaced content; no specific source file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.