Why would PsiFile be null for a VirtualFile?

Under what circumstances does this happen? My users are reporting
strange exceptions which are semi-reproducible, but only on their
machines. A null PsiFile is returned from PsiManager.findFile
consistently for the same VirtualFile in some cases, even though the
file exists.

4 comments
Comment actions Permalink

There may be several reasons, eq. file is ignored, no filetype
associated, (in a alibrary path?), (directory?), ...
Or maybe your custom language returns null from parsing?

Keith Lea schrieb:

Under what circumstances does this happen? My users are reporting
strange exceptions which are semi-reproducible, but only on their
machines. A null PsiFile is returned from PsiManager.findFile
consistently for the same VirtualFile in some cases, even though the
file exists.

0
Comment actions Permalink

I don't believe any of these are true. It's in sourcepath.

Sven Steiniger wrote:

There may be several reasons, eq. file is ignored, no filetype
associated, (in a alibrary path?), (directory?), ...
Or maybe your custom language returns null from parsing?

Keith Lea schrieb:

>> Under what circumstances does this happen? My users are reporting
>> strange exceptions which are semi-reproducible, but only on their
>> machines. A null PsiFile is returned from PsiManager.findFile
>> consistently for the same VirtualFile in some cases, even though the
>> file exists.

0
Comment actions Permalink

Please check vFile.isValid() is true (this is not the same as physical file being present on the disk). Another reason is ignored file as Sven already mentioned.

0
Comment actions Permalink

Eugene Vigdorchik wrote:

Please check vFile.isValid() is true (this is not the same as
physical file being present on the disk). Another reason is ignored
file as Sven already mentioned.


I'll add a log message. In the mean time, I'd like to know how can I
convert from an invalid VirtualFile to its existing valid counterpart?
This file which had null psifile certainly exists, so there must be a
VirtualFile for it. Is the solution to call
VfsUtil.findFileByUrl(VfsUtil.pathToUrl(file.getPath())) every time I
use a VirtualFile?

0

Please sign in to leave a comment.