Smart Pointers Expiration

I just caught a situation when SmartPointer doesnt't return a psi element, but the element is still alive. Is it possible?

I store some cached values in the psi element, and value provider uses smart pointer to the element to calculate the values. So the situation is following - after accessing the cached value it recalculates, but the pointer doesn't point to the element anymore and NPE is thrown.

0
1 comment
Official comment

Yes, smart pointers can be invalidated, and you shouldn't rely on them returning not-null PSI. If your PsiElement is still alive, valid, and points to the same place in the document, it might be a bug nevertheless: please provide as many details as possible.

BTW I wouldn't use smart pointers in your situation. Using directly those PSI elements in whose user data CV is stored is safe.

Please sign in to leave a comment.